Maybe instead of tobytes() you can use memoryview(). On Sun, Oct 10, 2021 at 08:21 Facundo Batista <[email protected]> wrote:
> El dom, 10 de oct. de 2021 a la(s) 11:50, Serhiy Storchaka > ([email protected]) 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 > _______________________________________________ > Python-Dev mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/[email protected]/message/52NGDRMD3BR4ZTT3KGF6FNNGQIIPXBWY/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido (mobile)
_______________________________________________ Python-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/5NTTZC54FNPSO3VDCF6NIJ75NKNTFIJY/ Code of Conduct: http://python.org/psf/codeofconduct/
