[C++-sig] create boost array from a Numpy PyArray without copying data?

Ravi lists_ravi at lavabit.com
Tue Jan 20 15:11:00 CET 2009


On Tuesday 20 January 2009 04:27:02 Sebastian Walter wrote:
> Thanks for the hint :),
> Your code is a little to heavyweight for my purposes,
> but I learned quite a lot how boost::python converters work.
>
> And it also gave me the idea that finally solved my problem!

Good.

> // global to guarantee that the data is not freed after
> test_function_that_doesnt_copy returns
> double x[] = {1.,2.,3.};

In this case, you run into the problem of lifetime management. Unless you use 
globals, how do you guarantee that once all users of the array are done with 
it, the array is deleted? The array must be deleted from either the python 
side (via numpy) or from the C++ side (by yourself). Handling this problem is 
the cause for much of my code (which may still be too heavyweight for you).

Regards,
Ravi




More information about the Cplusplus-sig mailing list