
On Sun, 10 Oct 2021 11:19:44 -0300 Facundo Batista <facundobatista@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.