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

Allow sendmsg to accept a preallocated Vec #2457

Open
vkrasnov opened this issue Jun 27, 2024 · 1 comment
Open

Allow sendmsg to accept a preallocated Vec #2457

vkrasnov opened this issue Jun 27, 2024 · 1 comment

Comments

@vkrasnov
Copy link

Currently sendmsg allocates a new vector for cmsg_buffer every time it is called. It would be nice if it could accept a mutable reference to Vec instead so it can reuse existing storage instead or &mut [u8], perhaps as an option?

@SteveLauC
Copy link
Member

SteveLauC commented Jul 10, 2024

Hi, it would be nice to avoid heap allocations here, but if we allow users to pass a pre-allocated cmsg buffer, then users have to ensure that:

  1. The buffer is zero-initialized
  2. The buffer is sufficient in size

For 1, Nix can guarantee this by (possibly) re-initializing it. For 2, if we use a vector and it is insufficient, we can re-allocate to extend the capacity.

Perhaps we should provide an alternative interface? Something like sendmsg_pre_alloc()?

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

No branches or pull requests

2 participants