Most effective way to write Packets.

12/05/2012 21:09 Danial Eugen#1
is it using Structs >?
12/06/2012 00:06 pro4never#2
It depends really. There's plenty of viable and effective ways of writing packets.

From a pure efficiency standpoint, I'm under the impression that structs and memory marshaling are likely king. I do know that it gets very painful to work with as soon as you start delving into variable offset packets though and therefor are less 'worth it'.

Personally I feel pointers are the best route to take and is actually what the TQ servers use (look at the NetStringPacker in Albetros source, that's ripped from tq sources by dev).


It really depends on what you value. What's most efficient for one packet (simple fixed offset/length packets) might be less efficient or difficult to work with on another (variable number of variable length strings for example)
12/06/2012 10:46 Super Aids#3
What pro said.

Just want to add that if your packet contains strings you should avoid structs IMO.
12/06/2012 13:12 CptSky#4
Sequential structures using a packing of one byte. For packets with variable length strings, putting a fixed char array of one byte at the end to use with a StringPacker would do the trick. After that, you can alloc the structure on the heap and cast it to an unsafe byte pointer OR you can stackalloc the structure and copy it to a managed byte array.

That's the way I mostly did it, and that's the way I would go.
12/06/2012 13:59 Korvacs#5
Effective in which way?

Memory usage.
Speed of creation/sending.
Ease of use.

All of these have different possible solutions.
12/06/2012 16:34 Danial Eugen#6
Quote:
Originally Posted by Korvacs View Post
Effective in which way?

Memory usage.
Speed of creation/sending.
Ease of use.

All of these have different possible solutions.
I might select speed of creation/sending... which is the same as ease of use
12/06/2012 16:55 Super Aids#7
Not really. Ease of use is the way you're using it, how easy it is to ex. implement etc.
12/07/2012 03:27 U2_Caparzo#8
i think u must use the way that is easier for u to use, actually almost every way to write packets are fast and don't has much memory usage, the difference won't be much, but the difficulty to structure them will be. (ofc this will apply in cases that u aren't writing an extremly crappy code)
12/07/2012 09:54 Korvacs#9
Ease of use would be the ease at which it is to write and maintain packet structures and how to access the data and manage it etc. So that would most likely be a class, a byte[] and a base class which each packet inherits from.

For speed of creation I would suggest a class with a pointer based system and you should implement a native method to send by pointer, instead of converting to array.

And for memory its a struct being used as a pointer, but which has a fixed layout.

Thats my view anyway.