Implement Buffer Protocol to Save Memory Copy
Opened this issue · 1 comments
william-silversmith commented
I believe the following line is causing two memory copies:
bytes_out = bytearray(bufviewf[:outbytes])[:outbytes]
If we instead return a bytes-like object that implements the buffer protocol we can save a copy.
https://cython.readthedocs.io/en/latest/src/userguide/buffer.html
william-silversmith commented
This is difficult to do without making a copy, after all, we have to allocate a buffer equal in size to the original buffer anyway to write to. However, we might not need to make an additional copy on top of it. It might be possible to use realloc
in order to shrink the existing buffer.