[issue1943] improved allocation of PyUnicode objects

Amaury Forgeot d'Arc report at bugs.python.org
Mon May 25 10:45:45 CEST 2009


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

Looking at the comments, it seems that the performance gain comes from
the removal of the double allocation which is needed by the current design.

Was the following implementation considered:
- keep the current PyUnicodeObject structure
- for small strings, allocate one chunk of memory:
sizeof(PyUnicodeObject)+2*length. Then set self->str=(Py_UNICODE*)(self+1);
- for large strings, self->str may be allocated separately.
- unicode_dealloc() must be careful and not free self->str if it is
contiguous to the object (it's probably a good idea to reuse the
self->state field for this purpose).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1943>
_______________________________________


More information about the Python-bugs-list mailing list