Hoyt Koepke wrote:
> This is a common use case for me as well.  What I've done (for the
> case of ints, doubles, etc.) is have a separate struct that emulates
> the vector<> in C++; there are associated functions that resize it,
> create it, etc.  Like vector<>, it allocates more space than needed
> for new members, and uses malloc and realloc as appropriate.  I then
> have a .d structure member, holding a pointer to the data, so in my
> code I just use v.d[i] to access the i'th element.  However, this
> approach is far from as elegant as I'd like it to be.
>
> Out of curiosity, how difficult would it be to implement a new
> container type that emulates python's list but only holds one time and
> would work with both PyObject* and c types?  Say vector[type] to
> distinguish it from list.  Here would be my wishlist, given my current
> use cases, in order of desirability.

I don't think such a type should be built into Cython itself, but should
be written as just another class in pyx and pxd files (which can be
shipped with Cython perhaps).

However, it seems to require templates/generics in Cython. So that would
be the place to start working. Unfortunately that would probably be some
work (on the order of a GSoC I think?), but I think that would be a much
better approach than hard-coding in a brand new vector type in Cython.

(This is when I usually state that I think it is better if we can properly
wrap STL though, which will hopefully be done something about in summer,
since the list of data structures which it would be nice to have doesn't
at all stop with vectors.)

Dag Sverre

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to