Skip to content

allow receiving messages to buffer instead of creating an owned vector#284

Open
bgkillas wants to merge 3 commits intoNoxime:masterfrom
bgkillas:master
Open

allow receiving messages to buffer instead of creating an owned vector#284
bgkillas wants to merge 3 commits intoNoxime:masterfrom
bgkillas:master

Conversation

@bgkillas
Copy link

@bgkillas bgkillas commented Oct 3, 2025

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

/// 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>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather this be the only implementation than the allocating one. A networking API at this level should not be allocating.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm saying we make said breaking change.

.collect()
}

pub fn receive_messages_to_buffer(&mut self, buffer: &mut Vec<NetworkingMessage>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

let count = sys::SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnPollGroup(
self.sockets,
self.handle,
self.message_buffer.as_mut_ptr(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why write to self.message_buffer instead of writing directly to the provided Vec?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Successfully merging this pull request may close these issues.

2 participants