
El dom, 10 de oct. de 2021 a la(s) 11:50, Serhiy Storchaka (storchaka@gmail.com) escribió:
10.10.21 17:19, Facundo Batista пише:
I have a long list of nums (several millions), ended up doing the following:
struct.pack_into(f'{len(nums)}Q', buf, 0, *nums)
Why not use array('Q', nums)?
You mean `array` from the `array` module? The only way I see using it is like the following:
shm = shared_memory.SharedMemory(create=True, size=total_size) a = array.array('Q', nums) shm.buf[l_offset:r_offset] = a.tobytes()
But I don't like it because of the `tobytes` call, which will produce a huge bytearray only to insert it in the shared memory buffer. That's why I liked `pack_into`, because it will write directly into the memory view. Or I'm missing something? Thanks! -- . Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org.ar/ Twitter: @facundobatista