[Python-Dev] String views

Josiah Carlson jcarlson at uci.edu
Fri Sep 2 05:55:05 CEST 2005

skip at pobox.com wrote:
>     >> I'm skeptical about performance as well, but not for that reason.  A
>     >> string object can have a referent field.  If not NULL, it refers to
>     >> another string object which is INCREFed in the usual way.  At string
>     >> deallocation, if the referent is not NULL, the referent is DECREFed.
>     >> If the referent is NULL, ob_sval is freed.
>     Michael> Won't work. A string may have multiple referrents, so a single
>     Michael> referent field isn't sufficient.
> Hmmm...  I implemented it last night (though it has yet to be tested).  I
> suspect it will work.  Here's my PyStringObject struct:

*cough* buffers with string methods *cough*  Seriously.  I know people
don't seem to like them much, but a buffer is a string view, an array
view, an mmap view, ...  It does /exactly/ what you suggest string views
should do, and it's already in Python.  With minor wrappers, one could
use string methods almost directly, or with modification of string
methods, buffers and strings could share methods.

 - Josiah

More information about the Python-Dev mailing list