[Python-Dev] pymalloc and overallocation (unicodeobject.c,2.139,2.140 checkin)

Martin v. Loewis martin@v.loewis.de
26 Apr 2002 20:57:39 +0200


Tim Peters <tim.one@comcast.net> writes:

> But Marc-Andre uses realloc at the end to return the excess.  The excess
> bytes will get reused (and some returned yet again) by the next
> overallocation, and so on.  

Right. I confused this with the fact that PyMem_Realloc won't return
the excess memory, so the extra bytes in a small string will be wasted
for the life time of the string object - that still could cause
significant memory wastage.

> MAL, you should keep in mind that pymalloc is also managing the small chunks
> in your scheme:  when you're fiddling with a 40-character Unicode string, an
> overallocation "by a factor of 4" only amounts to an 80-character UTF8
> string.  

[I guess this is a terminology, not a math problem: a 40 character
Unicode string has already 80 bytes; the UTF-8 of it can have up
to 160 bytes].

Regards,
Martin