This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson
Date 2008-11-27.12:14:42
SpamBayes Score 5.1779414e-11
Marked as misclassified No
Message-id <1227788101.62.0.102470807499.issue4445@psf.upfronthosting.co.za>
In-reply-to
Content
There are a number of places in Objects/stringobject.c where memory is 
allocated for a string of length n using:

PyObject_MALLOC(sizeof(PyStringObject) + n)

On my computer (OS X 10.5.5/Intel), and, I suspect, on most common 
platforms, the PyStringObject struct is going to contain some number of 
bytes (probably 3) of trailing padding;  the result is that the 
PyObject_MALLOC call above asks for 3 more bytes than are necessary, and 
on average the Python interpreter will waste 3 bytes of memory per string 
allocation.  Is there any reason not to replace these calls with:

PyObject_MALLOC(offsetof(PyStringObject, ob_sval) + n + 1)

instead?

Patch attached.
History
Date User Action Args
2008-11-27 12:15:01mark.dickinsonsetrecipients: + mark.dickinson
2008-11-27 12:15:01mark.dickinsonsetmessageid: <1227788101.62.0.102470807499.issue4445@psf.upfronthosting.co.za>
2008-11-27 12:14:44mark.dickinsonlinkissue4445 messages
2008-11-27 12:14:43mark.dickinsoncreate