buffer objects (C-API)

Discussion in 'Python' started by moerchendiser2k3, May 13, 2010.

  1. 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
     
    moerchendiser2k3, May 13, 2010
    #1
    1. Advertising

  2. moerchendiser2k3

    Carl Banks Guest

    On May 12, 7:33 pm, moerchendiser2k3 <googler.
    > wrote:
    > 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
     
    Carl Banks, May 13, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raja
    Replies:
    12
    Views:
    24,412
    John Harrison
    Jun 21, 2004
  2. Stuart D. Gathman

    Auto free Buffer objects in C API?

    Stuart D. Gathman, Jul 3, 2003, in forum: Python
    Replies:
    2
    Views:
    1,001
    Stuart D. Gathman
    Jul 7, 2003
  3. Replies:
    2
    Views:
    607
    sergejusz
    Mar 26, 2007
  4. Neal Becker

    buffer creates only read-only buffer?

    Neal Becker, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    415
    Neal Becker
    Jan 8, 2009
  5. xingye
    Replies:
    9
    Views:
    276
    Michael Lu
    Apr 19, 2004
Loading...

Share This Page