Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualwood_brian

Posted 08 August 2012 - 03:32 PM

What you read on "some random forums" was probably referring to generalised and/or automatic serialisation. Such tools may not designed for space optimisation. For example, they may not allow you to express domain specific knowledge such as the range of a "health" variable, etc.


All the serialization libraries I know of eliminate padding that compilers have added. They also allow marshalling of single bytes. They may not support bit level access though. I'm not aware of a library that supports that.

#1wood_brian

Posted 08 August 2012 - 03:31 PM

I will answer your question backwards:


... so serialization doesn't increase the size of the struct ?

Forget about structs. What you need to worry about is the amount of data on the wire. The data on the wire is a serialised form of the data in memory. Directly sending a struct is an extremely basic form of serialisation - one where the memory and serialised representations are identical. Though basic, It is not the most efficient.

A structure will often contain "padding bytes". These bytes are placed so that data can be efficiently accessed by the processor (or in some architectures, so that it can be accessed without triggering an error!). It is not necessary to send such padding on the wire. Another example is data ranges. Say you have a Player structure with a health member variable of type "int". On common toolchains, you will have a four byte variable. However, your game might only ever have health values in the range 0 to 100. Thus, you could efficiently encode the health in a single byte.

Serialisation can go beyond just bytes. You can serialise boolean values to individual bits. The aforementioned health value needs only 7 bits to encode the full range.

Finally, one you get out of the mentality of "sending" a "struct" to "serialise to a byte stream and send that", you can easily add compression as part of the serialisation process, which might save more space depending on the nature of the data.

Combining these, a hand rolled serialisation scheme will almost certainly be as space efficient, if not more so, than directly sending the source structure. A serialisation library, one with space efficiency as a design goal, should also be able to compete with the source structures on size.



... i read that serialization greatly increases the size of the struct so at the end is it worth it ?

Where did you read that?

on some random forums...

What you read on "some random forums" was probably referring to generalised and/or automatic serialisation. Such tools may not designed for space optimisation. For example, they may not allow you to express domain specific knowledge such as the range of a "health" variable, etc.


All the serialization libraries I know of eliminate padding that compilers have added. They also allow marshalling of single bytes. They may not support bit level access though. I'm not aware of a library that supports that.

PARTNERS