allow receiving messages to buffer instead of creating an owned vector#284
allow receiving messages to buffer instead of creating an owned vector#284bgkillas wants to merge 3 commits intoNoxime:masterfrom
Conversation
| /// Like `receive_messages`, however you provide the buffer which messages are extended off of. | ||
| /// the amount of messages received are based off of the capacity of the buffer. | ||
| /// the buffer is expected to be cleared after use. | ||
| pub fn receive_messages_to_buffer(&mut self, buffer: &mut Vec<NetworkingMessage>) { |
There was a problem hiding this comment.
I would rather this be the only implementation than the allocating one. A networking API at this level should not be allocating.
There was a problem hiding this comment.
sounds good i just didn't want to make a breaking change, if maintainer thinks this breaking change is warrented then i would change it
There was a problem hiding this comment.
Yeah I'm saying we make said breaking change.
| .collect() | ||
| } | ||
|
|
||
| pub fn receive_messages_to_buffer(&mut self, buffer: &mut Vec<NetworkingMessage>) { |
| let count = sys::SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnPollGroup( | ||
| self.sockets, | ||
| self.handle, | ||
| self.message_buffer.as_mut_ptr(), |
There was a problem hiding this comment.
Why write to self.message_buffer instead of writing directly to the provided Vec?
There was a problem hiding this comment.
the buffer you provide accepts NetworkingMessages instead of the *mut SteamNetworkingMessage, these are different sizes so i dont see how i can write to the provided vector
just a small optimization to allow yourself to manage a buffer for receiving messages while not running into such borrow checker errors from just returning the iterator as is, an example for how i use it is https://github.com/bgkillas/rmtg/blob/f0ff81f8d1afffb40848cd697ff1f59db1df686d/net/src/steam.rs#L116