[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

BinaryFormatter class is efficient ?

Ranjeet Chakraborty

7/6/2002 6:05:00 PM

I am using the BinaryFormatter class to serialize a few
objects(longs, ints doubles and some custom objects) to
MemoryStream. After serialized I retrieve the byte array
buffer and transport it via NetworkStreams.

MemoryStream msTest = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
formatter.TypeFormat = FormatterTypeStyle.TypesWhenNeeded;
long llLength = 1234;
formatter.Serialize(msTest, llLength);
//msTest.Length = 56 for long, 57 for double and 52 for
//int
I thought BinaryFormatter was supposed to be efficient in
terms of serialization size, unlike the SoapFormatter
which obviously is bigger because of the XML namespace
information.
If I'd have used raw structs(packed with longs, doubles
or other native data types) in a regular c++ program and
passed byte pointers to these structs through sockets,
the data transfer size would have been sum of sizeof of
all fields within the struct. This sizeof yields the
regular 4 bytes for ints and longs and 8 for doubles and
so on. This way the network payload stays small and I
dont transfer too much data.
Then why this huge size with BinaryFormatter for native
data types.
Any ideas ? anybody ?