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

[Feature]: Is there any way to recv data directly to an existing buffer? #2057

Open
noooop opened this issue Jan 22, 2025 · 0 comments
Open

Comments

@noooop
Copy link

noooop commented Jan 22, 2025

_recv_frame always creates a new Frame.

@cfunc
@inline
def _recv_frame(handle: p_void, flags: C.int = 0, track: bint = False) -> Frame:
    """Receive a message in a non-copying manner and return a Frame."""
    rc: C.int
    msg = zmq.Frame(track=track)
    cmsg: Frame = msg

    while True:
        with nogil:
            rc = zmq_msg_recv(address(cmsg.zmq_msg), handle, flags)
        try:
            _check_rc(rc)
        except InterruptedSystemCall:
            continue
        else:
            break
    return msg

This will result in one more copy of the data, which is not cool.

Is there any way to recv data directly to an existing buffer?

This way I can pass in the pre-allocated buffer instead of copying the data in the Frame to where it should go.

When using the C language API, you always need to prepare a buffer.

char buf [256];
nbytes = zmq_recv (socket, buf, 256, 0);
assert (nbytes != -1);

C language can always achieve all the things.

@noooop noooop changed the title Is there any way to recv data directly to an existing buffer? [Feature]: Is there any way to recv data directly to an existing buffer? Jan 22, 2025
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

1 participant