[Python-Dev] new buffer in python2.7

Kristján Valur Jónsson kristjan at ccpgames.com
Mon Nov 1 03:32:01 CET 2010


You just moved your copying down one level into stream.read().
This magic function must be implemented by possibly concatenating several "socket.recv()" calls.
This invariably involves data copying, either by "".join() or stringio.write()
K

-----Original Message-----
From: python-dev-bounces+kristjan=ccpgames.com at python.org [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of "Martin v. Löwis"
Sent: Friday, October 29, 2010 18:15
To: python-dev at python.org
Subject: Re: [Python-Dev] new buffer in python2.7
That is easy to achieve using the existing API:

def read_and_unpack(stream, format):
    data = stream.read(struct.calcsize(format))
    return struct.unpack(format, data)

> Otherwise, I'm +1 on your suggestion, avoiding copying is a good thing.

I believe my function also doesn't involve any unnecessary copies.




More information about the Python-Dev mailing list