This still isn't a completely direct write - you're still creating an array in
between which is then copied into shm, whereas struct.pack_into writes directly
into the shared memory with no intermediate buffer.
And unfortunately you can't do
shm.buf[l_offset:r_offset].cast('Q')[:] = nums
where nums is a plain Python iterable; it has to already be an array, so it
still requires a copy.
On 10/10/2021 16:57, Serhiy Storchaka wrote:
> 10.10.21 18:18, Facundo Batista пише:
>> 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?
> shm.buf[l_offset:r_offset].cast('Q')[:] = a
>
> or
>
> shm.buf[l_offset:r_offset] = memoryview(a).cast('B')
>
>
> _______________________________________________
> 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/A2XKNKG4C55VKII6VOXRR3XEP6VHIU43/
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
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/IAOHC7LGAKNXMIIGAZI3ALJ6MJVFEEBI/
Code of Conduct: http://python.org/psf/codeofconduct/