2020
10-09
10-09
Python如何发送与接收大型数组
问题你要通过网络连接发送和接受连续数据的大型数组,并尽量减少数据的复制操作。解决方案下面的函数利用memoryviews来发送和接受大数组:#zerocopy.pydefsend_from(arr,dest):view=memoryview(arr).cast('B')whilelen(view):nsent=dest.send(view)view=view[nsent:]defrecv_into(arr,source):view=memoryview(arr).cast('B')whilelen(view):nrecv=source.recv_into(view)view=view[...
继续阅读 >