On Sun, 10 Oct 2021 11:19:44 -0300 Facundo Batista <facundobati...@gmail.com> wrote: > Hello everyone! > > I need to pack a long list of numbers into shared memory, so I thought > about using `struct.pack_into`. > > Its signature is > > struct.pack_into(format, buffer, offset, v1, v2, ...) > > I have a long list of nums (several millions), ended up doing the following: > > struct.pack_into(f'{len(nums)}Q', buf, 0, *nums) > > However, passing all nums as `*args` is very inefficient [0]. So I > started wondering why we don't have something like: > > struct.pack_into(format, buffer, offset, values=values) > > which would receive the list of values directly.
Just use `numpy.frombuffer` with your shared memory buffer and write into the Numpy array? https://numpy.org/doc/stable/reference/generated/numpy.frombuffer.html When you're looking to efficiently handle large volumes of primitive values such as integers, chances are Numpy already has the solution for you. Regards Antoine. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/56TOXGB3T56KCE2UMGGGH3YAGHWQTWG3/ Code of Conduct: http://python.org/psf/codeofconduct/