> Out of curiosity, what happens if allocation fails, and C++ raises
> std::bad_alloc? In C++ if you have used new and delete outside
> constructors, it might give you memory leaks. In Cython I suppose the
> C++ exception goes uncaught, so the program just crashes. I would use
> Python lists or NumPy arrays instead.


Python Lists are way too inefficient (memory-wise and
computation-wise) for my use case. NumPy array could have been an
option. But using a std::vector wrapped in a python extension allows
me to easily re-use a lot of code pre-written for c++. It's probably
possible to adapt a STL interface to a NumPy array structure to
achieve the same effect, but I haven't looked into that yet. However,
some of my uses involve vectors of vectors of different size, and
vectors of complex objects, for which Numpy arrays are not a very good
replacements.

As for catching std::bad_alloc: this is mostly research code, so I
have not been trying too hard to bulletproof my code against all
possible exceptions for now. However, wouldn't a try/catch block be
enough to handle this? Also, I believe there is a mechanism in
cython0.13 to automatically  convert c++ exceptions to python ones (by
declaring "except +").
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to