[Python-3000] Immutable bytes type and dbm modules
talin at acm.org
Tue Aug 7 05:50:27 CEST 2007
Martin v. Löwis wrote:
>> The most efficient representation of immutable bytes is quite different
>> from the most efficient representation of mutable bytes.
> In what way?
Well, in some runtime environments (I'm not sure about Python), for
immutables you can combine the object header and the bytes array into a
single allocation. Further, the header need not contain an explicit
pointer to the bytes themselves, instead the bytes are obtained by doing
pointer arithmetic on the header address.
For a mutable bytes object, you'll need to allocate the actual bytes
separately from the header. Typically you'll also need a second 'length'
field to represent the current physical capacity of the allocated memory
block, in addition to the logical length of the byte array.
So in other words, the in-memory layout of the two structs is different
enough that attempting to combine them into a single struct is kind of
More information about the Python-3000