Binary Serialized file much larger than expected

S

Stewart

Hi,

I have a class which has 6 automatic properties (6 x 8 bytes). This
means the total size of the class is 48 bytes. I have 15000 of these
in a generic List. When I serialize these to disc using the
BinaryFormatter I get a file which is 970kb. I would have expected
closer to 48 * 15000 / 1000 = 720kb.

Thoughts?

Stewart
 
J

Jeff Johnson

I have a class which has 6 automatic properties (6 x 8 bytes). This
means the total size of the class is 48 bytes. I have 15000 of these
in a generic List. When I serialize these to disc using the
BinaryFormatter I get a file which is 970kb. I would have expected
closer to 48 * 15000 / 1000 = 720kb.

Did you open the output in a hex viewer to see what its contents looked
like?
 
J

Jeff Johnson

I have a class which has 6 automatic properties (6 x 8 bytes). This
means the total size of the class is 48 bytes. I have 15000 of these
in a generic List. When I serialize these to disc using the
BinaryFormatter I get a file which is 970kb. I would have expected
closer to 48 * 15000 / 1000 = 720kb.

[Sent my reply too soon]

1K = 1024, so divide by that, not 1000 (the difference would not turn 970
into 720, but it's still better to be correct).

Finally, how about serializing just one class and seeing how big that is,
then serializing 2 and seeing what the difference is. Exactly 2x? Something
else?
 
A

Arne Vajhøj

I have a class which has 6 automatic properties (6 x 8 bytes). This
means the total size of the class is 48 bytes. I have 15000 of these
in a generic List. When I serialize these to disc using the
BinaryFormatter I get a file which is 970kb. I would have expected
closer to 48 * 15000 / 1000 = 720kb.

You forget that you need metadata in the serialized bytes to
describe what the data is.

Arne
 
R

Rick Lones

Stewart said:
Hi,

I have a class which has 6 automatic properties (6 x 8 bytes). This
means the total size of the class is 48 bytes. I have 15000 of these
in a generic List. When I serialize these to disc using the
BinaryFormatter I get a file which is 970kb. I would have expected
closer to 48 * 15000 / 1000 = 720kb.

Thoughts?

Stewart

"This means the total size of the class is 48 bytes." I think I would view it
as: "The minimum required storage for the fields of the class is 48 bytes."
They are not the same thing.

Did you expect it (binary serialization) to be completetely free of overhead?
Your numbers work out to only about 16 bytes of overhead per object. That seems
very modest to me, but of course your example is very simple.

-rick-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top