[Python-Dev] The buffer() function (original) (raw)

Thomas Heller theller at python.net
Thu Jul 13 20:51:42 CEST 2006


Josiah Carlson schrieb:

Thomas Heller <theller at python.net> wrote:

But that was not the question. What about the status of the buffer function?

From what I understand, it is relatively safe as long as you don't mutate an object while there is a buffer attached to it. That is: import array a = array.array(...) b = buffer(a) for i in xrange(...): a.extend(a[:]) print str(b) ... may cause you some problems (the a[:] bit was to pointer movement movement on realloc). Those problems will depend on your platform.

AFAIK, the buffer object now does not hold a pointer into the object it has been constructed from, it only gets it when its needed.

IMO Objects/bufferobject.c, revision 35400 is considered safe.

The checkin comment (by nascheme) was, more than 2 years ago: "Make buffer objects based on mutable objects (like array) safe."

Thomas



More information about the Python-Dev mailing list