
On Sun, Oct 10, 2021 at 4:23 PM Facundo Batista <facundobatista@gmail.com> wrote:
struct.pack_into(format, buffer, offset, v1, v2, ...)
I've encountered this wart with pack and pack_into too. The current interface makes sense when if v1, v2 are a small number of items from a data record, but it becomes a bit silly when v1, v2, ... are the elements of an array of 10 000 integers, for example. The option to take a list-like argument like you suggest is a good idea, but maybe this should have its own function or is just outside the scope of the built-in struct module. Multiprocessing sort of added support for this via multiprocessing.Array -- see https://stackoverflow.com/questions/9754034/can-i-create-a-shared-multiarray.... I haven't looked at what multiprocessing.Array does under the hood. Summary of the StackOverflow answer for those who don't feel like clicking: mp_arr = mp.Array(c.c_double, size) # then in each new process create a new numpy array using: arr = np.frombuffer(mp_arr.get_obj()) - Simon