New submission from Mark Dickinson <[EMAIL PROTECTED]>: 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. ---------- components: Interpreter Core files: string_alloc.patch keywords: patch messages: 76495 nosy: marketdickinson severity: normal status: open title: String allocations waste 3 bytes of memory on average. type: performance versions: Python 2.6, Python 2.7 Added file: http://bugs.python.org/file12140/string_alloc.patch _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4445> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com