nix
nix copied to clipboard
Allow `sendmsg` to accept a preallocated `Vec`
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?
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:
- ~~The buffer is zero-initialized~~
- 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()?
The buffer is zero-initialized
Cannot remember why I said this is needed, I think we do not need to satisfy this condition.