On 4/19/07, Bill Baxter firstname.lastname@example.org wrote:
What's the right way to make a new numpy array that's a copy of some C data?
There doesn't seem to be any API like PyArray_NewFromDescr that /copies/ the void*data pointer for you. Do I have to write my own loops for this? I can do that, it just seems like it should be a library function already, so I'm guessing I'm just overlooking it. There seem to be lots of APIs that will wrap pre-existing memory, but the ones that allocate for you do not seem to copy.
A related question -- I'm only trying to copy in order to save myself a little hassle regarding how to clean up the allocated chunks. If there's some simple way to trigger a particular deallocation function to be called at the right time, then that would be the ideal, really. Does that exist?
This is a situation I have been waiting to address for a long time ! In our case the data size is generally considered to be to large to accept the copy-solution. A cookbook-wiki entry would be wonderful! Generally we would have data memory that was allocated via alloc() and data that was allocated via new -- so two different deallocation functions (free() and delete, respectively) would be required for this to be trigged, once the reference counter goes back to zero.
Thanks, Sebastian Haase