buffer objects (C-API)

M

moerchendiser2k3

Hi at all,

is it possible that a buffer object deallocates the memory when the
object is destroyed? I want to wrap the buffer object around some
memory. Or is there any chance that the buffer object copies the
memory so it will be responsible when it will be destroyed?

Thanks in advance, bye.

moerchendiser2k3
 
C

Carl Banks

Hi at all,

is it possible that a buffer object deallocates the memory when the
object is destroyed? I want to wrap the buffer object around some
memory. Or is there any chance that the buffer object copies the
memory so it will be responsible when it will be destroyed?


Objects that support the buffer protocol will only deallocate their
memory if they're programmed to.

If you're writing your own buffer type you can be assured the memory
won't be deallocated unless you do it yourself.

If you're referring to the Python 2.x "buffer" object, no it won't
deallocate the memory. You should also be aware that it's deprecated
in 2.x and removed in 3.x.

Generally speaking, objects that allocate their own memory should also
deallocate it; objects that are passed pointers to existing memory
should leave it alone. Most built-in types in Python that support
buffer protocol do allocate their own memory, so they also deallocate
it. "buffer" doesn't, so it doesn't.

One other thing to consider is numpy, especially if your buffer is
numeric. It might even have the operations you need already.
numpy.ndarray can allocate its own memory or accept a pointer (or
other buffer object), and will only delete the buffer if it allocated
it itself.


Carl Banks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top