Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2006

Tip: Looking for answers? Try searching our database.

Question about data size when using serialized writing using BinaryFormatter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken Varn - 02 Nov 2006 16:02 GMT
I am writing a structure marked as serializable to a data file using the
BinaryFormatter.  The structure does not inherit from any other types.  If I
were to add up the byte size of all the data contained within the structure,
I get about 50 bytes.  However, when I write the data to the file with
BinaryFormatter, the resulting file size is much more (around 229 bytes).

Can someone explain why the resulting size of the written data is so large?
I am assuming that maybe some other data is written from the base Object
class, but it still seems quite excessive.

Is there anyway to trim down the size of data written to be more efficient
with the storage during serialization?

Signature

-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------

Günter Prossliner - 02 Nov 2006 17:07 GMT
Hi Ken!

> I am writing a structure marked as serializable to a data file using
> the BinaryFormatter.  The structure does not inherit from any other
[quoted text clipped - 5 lines]
> Can someone explain why the resulting size of the written data is so
> large?

As Vadym pointed out, the metadata serialization takes some space.

> Is there anyway to trim down the size of data written to be more
> efficient with the storage during serialization?

You can implement ISerializable. Within the GetObjectData() method, you
perform a custom serialization (maybe with minimal metadata - or even no
metadata when you know the size and the position of all elements) within a
byte - Array. This byte Array you can add to the SerializationInfo object in
one call.

Even if the .Net Infrastructure adds metadata for the byte-Array, it is much
smaller!

GP
Ken Varn - 03 Nov 2006 17:10 GMT
I tried implementing ISerializable in my class, but still yield about the
same size.  How do you reduce the amount of data that the Serialization
object provides?

I have a StructLayout attribute on my class and thought that maybe I could
somehow tie that into serialization in a similar way it is used for
marshalling, but that is not available.

Signature

-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------

Hi Ken!

> I am writing a structure marked as serializable to a data file using
> the BinaryFormatter.  The structure does not inherit from any other
[quoted text clipped - 5 lines]
> Can someone explain why the resulting size of the written data is so
> large?

As Vadym pointed out, the metadata serialization takes some space.

> Is there anyway to trim down the size of data written to be more
> efficient with the storage during serialization?

You can implement ISerializable. Within the GetObjectData() method, you
perform a custom serialization (maybe with minimal metadata - or even no
metadata when you know the size and the position of all elements) within a
byte - Array. This byte Array you can add to the SerializationInfo object in
one call.

Even if the .Net Infrastructure adds metadata for the byte-Array, it is much
smaller!

GP

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.