Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for memoryview? #79

Open
ZisIsNotZis opened this issue Dec 8, 2020 · 2 comments
Open

Support for memoryview? #79

ZisIsNotZis opened this issue Dec 8, 2020 · 2 comments

Comments

@ZisIsNotZis
Copy link

It would be nice to have memoryview supported to support zero-copying. Currently it seems that only bytes are supported which can't share memory with other objects

@codypiersall
Copy link
Owner

Do you mean for the methods Socket.send() and Socket.asend()? (and similarly for the pipe and context methods?) Or did you have something else in mind?

@sk1p
Copy link

sk1p commented Oct 25, 2021

It is possible to use a memoryview for sending - currently, you need to pierce through the abstraction and use the ffi instance from pynng in your user code, to convert it into an object that is understood by cffi. For example like this:

from pynng import ffi
import numpy as np

data = np.zeros(128)  # or whatever - just needs to support the buffer protocol
mv = memoryview(data)
your_socket.send(ffi.from_buffer(mv))

Maybe this could be directly supported in the send method, by wrapping the object to send into a from_buffer if it is a memoryview? Or even directly support objects that implement the buffer protocol, so one can directly call your_socket.send(some_numpy_array)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants