[Python-Dev] Wild Idea for the Year
Armin Rigo
arigo at tunes.org
Thu Jun 24 05:43:15 EDT 2004
Hello Raymond,
On Sat, Jun 19, 2004 at 03:40:07PM -0400, Raymond Hettinger wrote:
> * resize self to be big enough for an ob_sized string
How would you do that? I can't see how you can resize strings in-place, and
if the strings are pre-allocated to have the correct length you only solve one
side of the problem -- the copy overhead -- and not the other one --
allocating and deallocating larger and larger blocks of memory.
Solving half the problem would already be nice. Note however that code
everywhere expects strings to have characters in their ob_sval field,
accessing it thought the PyString_AS_STRING() macro. You could fix that macro
too, but you would have to carefully monitor the performance impact.
> If this works out, it would be an innovation. The join([a,b]) versus
> a+=b problem also exists in several other languages. AFAICT, Python
> would have been the first to solve it.
*cough* Psyco *cough* implementation versus language *cough*
I don't think Python can pretend to have put a lot of research effort into its
string objects. Someone mentioned C++'s ropes, for example. Moreover there
are a number of papers out there about which kind of structures are best
suited in which situations, which should probably be taken into account too.
(Psyco uses over-allocated buffers.)
Armin
More information about the Python-Dev
mailing list