Re: Binary serialization
- From: Jacques <Jacques@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 27 Jun 2006 03:03:01 -0700
Thanks for the prompt response.
From what I can deduce from your answer below, the answer to my question isyes? I.e. every unique managed object I create needs its own streamwriter
(and thus streamreader) routine if the desired result is to store its DATA
MEMBERS ONLY! Sorry for my pessimism about the error prone-ness of the above,
but this new (for me) approach involves significantly more work for me!
Thanks for clearing things up though!
Jacques
"Frans Bouma [C# MVP]" wrote:
Jacques wrote:.
Hi
You are correct in assuming that I don't want do save files of 8
bytes! I am writing a realtime data capture app and need to minimise
disk space. Previously I would use a file write routine that worked
similarly to memcpy, ie "File.Write(&MyClass,sizeof(MyClass))".
My question is this: Is the only way in which I can extract ONLY the
DATA members from the class in question the method of writing each
individual data member to astream/file.. MYSELF? The problem I have
with this is twofold: 1. every custom object needs its own custom
streamwriter routine 2. point nr (1) is quite error prone for a
clumsy programmer like myself!
You can somewhat solve it quite elegantly with the strategy pattern
through some base class/subclass construction: in the base class you
create the stream writer code, in the subclass you override a method of
the base class where you collect the data in to a byte array which is
then written to the stream by the base class. I dont see how that can
go wrong :)
FB
Kind regards
Jacques
"Frans Bouma [C# MVP]" wrote:> Jacques wrote:
Hi
I am an dotNet newby, so pardon my ignorance.
I am looking for a method of saving/copying a managed class to a
stream/file WITHOUT saving the object's state, eg. if I have a ref
class with two int32's as its data members, the binary file of
that class must have a size of 8 bytes (i.e. only contains class
data members, not methods etc.).
Is serialization the answer to the above problem?
No.
Binary serialization is a mechanism which writes that data to the
output stream which is necessary to re-create the object when
reading that precise data. I.o.w.: you get the contents + extra
fluff. If you want to save 8 bytes, you should grab the 8 bytes and
write them yourself. Though I fail to see the necessity for files
of 8 bytes. This thus leads to the assumption that you want to save
the data of a lot of objects into one file. If you do that
yourself, you can end up with a compact file, but also with a lot
of code, or better: more code than you would end up with when you
would just go for the binary formatter approach.
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
- Follow-Ups:
- Re: Binary serialization
- From: Frans Bouma [C# MVP]
- Re: Binary serialization
- From: Kevin Spencer
- Re: Binary serialization
- References:
- Re: Binary serialization
- From: Frans Bouma [C# MVP]
- Re: Binary serialization
- From: Frans Bouma [C# MVP]
- Re: Binary serialization
- Prev by Date: Re: test
- Next by Date: Re: What is the standard for naming objects?
- Previous by thread: Re: Binary serialization
- Next by thread: Re: Binary serialization
- Index(es):
Relevant Pages
|