[Python-Dev] cStringIO buffer interface

Jean-Paul Calderone exarkun at divmod.com
Wed Apr 30 20:38:04 CEST 2008

On Wed, 30 Apr 2008 09:51:25 -0700, Guido van Rossum <guido at python.org> wrote:
>On Wed, Apr 30, 2008 at 9:36 AM, Farshid Lashkari <flashk at gmail.com> wrote:
>>  I was just curious as to why cStringIO objects don't implement the
>>  buffer interface.  cStringIO objects seem similar to string and array
>>  objects, and those support the buffer protocol. Is there a reason
>>  against allowing cStringIO to support at least the read buffer
>>  interface, or is just that nobody has considered it until now?
>Well, for one, it would mean you could no longer exchange a StringIO
>instance for a cStringIO instance.

It would probably only mean that there is one further incompatibility
between cStringIO and StringIO - you already can't exchange them in a
number of cases.  They handle unicode differently, they have different
methods, etc.

Maybe making them diverge even further is a step in the wrong direction,

>Also, what's the compelling use case you're thinking of?

I'm not sure what use-case Farshid Lashkari had.  For Twisted, it has
been considered as a way to reduce peak memory usage (by reducing the
need for memory copying, which also speeds things up).  I'm not sure
if anyone has benchmarked this yet, so I don't know if it's a real win
or not.  I think Thomas Hervé has a patch to cStringIO which implements
the feature, though.

For reference, <http://twistedmatrix.com/trac/ticket/3188>.

This isn't high on my priority list, but I thought I'd point out the
potential use-case.


More information about the Python-Dev mailing list