nix icon indicating copy to clipboard operation
nix copied to clipboard

Allow `sendmsg` to accept a preallocated `Vec`

Open vkrasnov opened this issue 1 year ago • 2 comments
trafficstars

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?

vkrasnov avatar Jun 27 '24 18:06 vkrasnov

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()?

SteveLauC avatar Jul 10 '24 02:07 SteveLauC

The buffer is zero-initialized

Cannot remember why I said this is needed, I think we do not need to satisfy this condition.

SteveLauC avatar Sep 15 '24 08:09 SteveLauC