A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-November/105137.html below:

[Python-Dev] new buffer in python2.7

[Python-Dev] new buffer in python2.7Kristján Valur Jónsson kristjan at ccpgames.com
Mon Nov 1 10:09:31 CET 2010
Ah, yes.  There are, in my case.  (why do I always seem to be doing stuff that is different from what you all are doing:)
The particular piece of code is from the chunked reader. It may be reading rather large chunks at a time (several lots of Kb.):

def recvchunk(socket):
    len = socket.unpack('i', recv_exactly(socket, 4))
    return recv_exactly(len)

#old style
def recv_exactly(socket, length):
    data = []
    while length:
        got = socket.receive(length)
        if not got: raise EOFError
        data.append(got)
        length -= len(got)
    return "".join(data)

#new style
def recv_exactly(socket, length):
    data = bytearray(length)
    view = memoryview(data)
    while length:
        got = socket.receive_into(view[-length:])
        if not got: raise EOFError
        length -= len(got)
    return data


Here I spot another optimzation oppertunity:  let memoryview[:] return self, since the object is immutable, I believe.
K

> -----Original Message-----
> From: "Martin v. Löwis" [mailto:martin at v.loewis.de]
> Sent: 1. nóvember 2010 14:22
> To: Kristján Valur Jónsson
> Cc: python-dev at python.org
> Subject: Re: [Python-Dev] new buffer in python2.7
> 
> 
> Assuming there are multiple recv calls. For a typical struct, all data
> will come out of the stream with a single recv. so no join will be
> necessary.
> 
> Regards,
> Martin

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4