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.

1. Very fast c level element access using []. Specifically, as fast as
C array access if it holds a C data type and as fast as list if
holding a python type.
2. All memory management issues handled automatically.
3. List-like methods -- append, pop, del, etc.  -- that avoid any
python overhead except possible ref counting stuff.
4. Ability to convert to and from python list in interfacing with
python code (doesn't need to be the fastest, but would have in-bulk
type checking / C--PyObject* conversions where needed).
5. Slicing that works like list's slicing.

I suspect there are tons of hidden issues behind each of these, and I
also understand it would be good to do get other issues out of the way
in this.  I am quite busy currently due to classes, research, and an
upcoming prelim exam, but would be happy to put some time into this if
someone can mentor me.  I've been meaning to get more into cython
development for a long time but am always too busy, so I might as well
start sometime.

--Hoyt

++++++++++++++++++++++++++++++++++++++++++++++++
+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ [email protected]
++++++++++++++++++++++++++++++++++++++++++
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to