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

Use only one physical packet per sf::Packet #119

Closed
pvoigtlaender opened this Issue Nov 2, 2011 · 2 comments

Comments

Projects
None yet
3 participants
@pvoigtlaender

pvoigtlaender commented Nov 2, 2011

sf::TcpSocket uses two physical packets to send one sf::Packet. To save bandwith these packets should be merged.
http://www.sfml-dev.org/forum/viewtopic.php?t=6148

@ghost ghost assigned LaurentGomila Nov 2, 2011

@retep998

This comment has been minimized.

Show comment
Hide comment
@retep998

retep998 Nov 2, 2011

As a suggestion on how to implement it better:
Always resize to size+4
Store the data starting from ptr+4
GetData returns ptr+4
This way you have room for the packet size without ever having to shift data and do further memory allocations.
Just write in the size when you're sending the packet, and off it goes.
You could also eliminate the size variable and just always use the first 4 bytes of the data for the size, so you won't use up any extra space.
The only overhead to this is a tiny bit of pointer arithmetic, but it's all fairly constant so the compiler will optimize it out mostly.

retep998 commented Nov 2, 2011

As a suggestion on how to implement it better:
Always resize to size+4
Store the data starting from ptr+4
GetData returns ptr+4
This way you have room for the packet size without ever having to shift data and do further memory allocations.
Just write in the size when you're sending the packet, and off it goes.
You could also eliminate the size variable and just always use the first 4 bytes of the data for the size, so you won't use up any extra space.
The only overhead to this is a tiny bit of pointer arithmetic, but it's all fairly constant so the compiler will optimize it out mostly.

@pvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@pvoigtlaender

pvoigtlaender Nov 2, 2011

That's a very good idea. For Udp sockets you can pass the buffer without the first 4 bytes as udp automaticully transfers the packet size and for tcp just use the whole buffer.

pvoigtlaender commented Nov 2, 2011

That's a very good idea. For Udp sockets you can pass the buffer without the first 4 bytes as udp automaticully transfers the packet size and for tcp just use the whole buffer.

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