[Python-Dev] PEP 296 - The Buffer Problem

Scott Gilbert xscottg@yahoo.com
Tue, 23 Jul 2002 08:40:55 -0700 (PDT)


--- Thomas Heller <thomas.heller@ion-tof.com> wrote:
> > PEP: 296
> > Title: The Buffer Problem
> 
> IMO should better be 'The bytes Object'
> 

Part of the title was just me being cute, but apparently this problem has a
long history and has been referred to as "The Buffer Problem" many times in
the past.  Plus when I first submitted it, I wasn't sure the name "bytes"
was going to stick.


> 
> Why is this? Wouldn't it be sufficient if views keep references
> to the 'viewed' byte object?
> 

They do, but the referenced "inner-thing" needs it's own reference count to
know how many "bytes-views" are sharing it.  When a bytes-view gets cleaned
up, it decrefs the reference count of the inner-thing it is referring to,
and if the reference count goes to zero, the bytes-view calls the
destructor for the inner-thing.


>
> > and this returns an int as well.  As a workaround, the bytes object
> > will provide a .length() method that will return a long.
> > 
> Is this worth the trouble?
> (Hm, 64-bit platforms with 32-bit integers remind my of the broken
> DOS/Windows 3.1 platforms with near/far/huge pointers).
> 

I think most 64 bit platforms actually have a 32 bit int.  Some of them
(like the Alpha) have a 64 bit long, but Python has made extensive use of
the int type in the PyBufferProcs interface and elsewhere.  So if we want
to make full use of large memory machines (I do), something has to be done.
 The only way to reliably get a 64 bit integer on these platforms is to use
the "long long" type or __int64 on Windows (spelled LONG_LONG in Python).

Note that the .length() method will return a Python long, not a C long.


> 
> Shouldn't there be constructors to create a view of a bytes/view object,
> or are we supposed to create them by slicing?
> 

Item 9 in the PEP talks about this.  Maybe I'll add some text to make this
more clear.



Cheers,
    -Scott


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com