473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Binary serialization

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? If I understand correctly,
the reason that pointer arithmetic and operations like sizeof(MyRefClass)
don't work is that the managed class is handled by the CLR, which, in turn,
requires objects to be serialized before porting.

In short, is there a serialization method which enables me to store ref
class data members ONLY in the same way as in native C++ (memcpy,etc.) does?

Thanks!
Jacques
Jun 26 '06 #1
15 2361
Bonjour Jacques,

It sounds like what you need is a class that implements the ISerializable
interface, and custom Serialization. The following articles and references
should help:

The System.Runtime.Serialization Namespace:
http://msdn2.microsoft.com/en-us/lib...alization.aspx

Custom Serialization:
http://msdn2.microsoft.com/en-us/library/ty01x675.aspx

ISerializable.GetObjectData:
http://msdn2.microsoft.com/en-us/lib...bjectdata.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Jacques" <Ja*****@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
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? If I understand
correctly,
the reason that pointer arithmetic and operations like sizeof(MyRefClass)
don't work is that the managed class is handled by the CLR, which, in
turn,
requires objects to be serialized before porting.

In short, is there a serialization method which enables me to store ref
class data members ONLY in the same way as in native C++ (memcpy,etc.)
does?

Thanks!
Jacques

Jun 26 '06 #2
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.

FB

--
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------
Jun 26 '06 #3
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!

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.

FB

--
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------

Jun 27 '06 #4
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#)
------------------------------------------------------------------------
Jun 27 '06 #5
Jacques,

You need to save space on disk. You are aware that making programs complex
makes them need more space on disk.

In past I have seen this done many times by programmers with memory. They
wanted to use a minimum size for data areas in memory. The routines they
used where mostly spending more memory as the area would have been as they
had used the standard methods.

Just my thought on that reading your message.

Cor
"Jacques" <Ja*****@discussions.microsoft.com> schreef in bericht
news:15**********************************@microsof t.com...
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!

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.

FB

--
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------

Jun 27 '06 #6
Thanks for the prompt response.

From what I can deduce from your answer below, the answer to my question is
yes? 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#)
------------------------------------------------------------------------

Jun 27 '06 #7
I told you yesterday that you could do this with custom binary
serialization.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Jacques" <Ja*****@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
Thanks for the prompt response.

From what I can deduce from your answer below, the answer to my question
is
yes? 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#)
------------------------------------------------------------------------

Jun 27 '06 #8
Jacques wrote:
Thanks for the prompt response.

From what I can deduce from your answer below, the answer to my
question is yes? 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!
Yes then you need your own streamwriter/reader combo. It will be
significantly faster than the binary formatter, so I think it's worth
the try.

FB

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#)
------------------------------------------------------------------------
Jun 27 '06 #9
Yes, thanx, I just find it difficult to understand why it necessary for me
implement a custom serialisation method for every object I create if the the
objects's DATA members are the only part of the object I want to store.

Nevertheless, thanx again, I was just looking for a simpler solution. :)

Jacques

"Kevin Spencer" wrote:
I told you yesterday that you could do this with custom binary
serialization.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Jacques" <Ja*****@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
Thanks for the prompt response.

From what I can deduce from your answer below, the answer to my question
is
yes? 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#)
------------------------------------------------------------------------


Jun 27 '06 #10
The problem here is that you're working with managed objects. So, you can't
just memcopy as you would with C++. One of the advantages of using Binary
Serialization in managed code is that the object can be de-serialized from
the same data you serialized it to. There are others as well. It's really
not hard to do.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Jacques" <Ja*****@discussions.microsoft.com> wrote in message
news:88**********************************@microsof t.com...
Yes, thanx, I just find it difficult to understand why it necessary for me
implement a custom serialisation method for every object I create if the
the
objects's DATA members are the only part of the object I want to store.

Nevertheless, thanx again, I was just looking for a simpler solution. :)

Jacques

"Kevin Spencer" wrote:
I told you yesterday that you could do this with custom binary
serialization.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Jacques" <Ja*****@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
> Thanks for the prompt response.
>
> From what I can deduce from your answer below, the answer to my
> question
> is
> yes? 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#)
>> ------------------------------------------------------------------------
>>


Jun 27 '06 #11
Kevin Spencer wrote:
The problem here is that you're working with managed objects. So, you
can't just memcopy as you would with C++. One of the advantages of
using Binary Serialization in managed code is that the object can be
de-serialized from the same data you serialized it to. There are
others as well. It's really not hard to do.


It was my understanding he wanted to have ONLY the 8 bytes of data
contained in the object into the file, not a bit more or less. You then
can't use binary serialization as that adds more bytes to the file, per
object.

Another thing that makes binary serialization in this case useless is
that the more objects you have to deserialize, the slower it gets. If
you have hundreds of thousands of objects with 8 bytes, deserializing
them will bring the app to its knees for minutes, while reading the
file from front to back and creating a new object for every 8 bytes you
read is much faster.

FB

--
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------
Jun 28 '06 #12
Hi guys,

I don't understand why making all that trouble if you just want some items
from an object in a file from 8 bytes. (Although I doubt that any file
system will not expand that on disk to the minimum default).

In my idea are there than more classic very simple methods we did already
use with the punchcard.

:-)

Cor

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> schreef in bericht
news:xn***************@news.microsoft.com...
Kevin Spencer wrote:
The problem here is that you're working with managed objects. So, you
can't just memcopy as you would with C++. One of the advantages of
using Binary Serialization in managed code is that the object can be
de-serialized from the same data you serialized it to. There are
others as well. It's really not hard to do.


It was my understanding he wanted to have ONLY the 8 bytes of data
contained in the object into the file, not a bit more or less. You then
can't use binary serialization as that adds more bytes to the file, per
object.

Another thing that makes binary serialization in this case useless is
that the more objects you have to deserialize, the slower it gets. If
you have hundreds of thousands of objects with 8 bytes, deserializing
them will bring the app to its knees for minutes, while reading the
file from front to back and creating a new object for every 8 bytes you
read is much faster.

FB

--
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------

Jun 28 '06 #13
Hi Frans,

Perhaps I misunderstood. He was talking about serializing a class, but from
what I gather it sounds like he just wants to serialize the data. If you
only serialize the data, you can't deserialize it back to a class. But there
are certainly times when it's useful to do what you're describing. So, since
you seem to have a better picture of what he wants to do, I'll just leave it
to you. :-)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@news.microsoft.com...
Kevin Spencer wrote:
The problem here is that you're working with managed objects. So, you
can't just memcopy as you would with C++. One of the advantages of
using Binary Serialization in managed code is that the object can be
de-serialized from the same data you serialized it to. There are
others as well. It's really not hard to do.


It was my understanding he wanted to have ONLY the 8 bytes of data
contained in the object into the file, not a bit more or less. You then
can't use binary serialization as that adds more bytes to the file, per
object.

Another thing that makes binary serialization in this case useless is
that the more objects you have to deserialize, the slower it gets. If
you have hundreds of thousands of objects with 8 bytes, deserializing
them will bring the app to its knees for minutes, while reading the
file from front to back and creating a new object for every 8 bytes you
read is much faster.

FB

--
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------

Jun 28 '06 #14
Kevin Spencer wrote:
Hi Frans,

Perhaps I misunderstood. He was talking about serializing a class,
but from what I gather it sounds like he just wants to serialize the
data. If you only serialize the data, you can't deserialize it back
to a class. But there are certainly times when it's useful to do what
you're describing. So, since you seem to have a better picture of
what he wants to do, I'll just leave it to you. :-)


heh :) I think his main confusion comes from the fact that in MFC you
also could implement serialization but that was solely about the data
and resulted in implementing datareader/writers so no class info ended
up in the output stream if you didn't want to. (if my rusty MFC memory
still functions correctly ;))

in .NET you either have to do manual writing/reading the data (which
is actually pretty straight forward in this case IMHO) or accept class
info in the output.

FB

--
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------
Jun 28 '06 #15
Thanx very much for all the replies - these clarify things for me
signficantly, i.e. I will implement binary serialization method for every
object I create to store only the data members of that object, without any
class info.

Kind regards
Jacques van Wyk

"Frans Bouma [C# MVP]" wrote:
Kevin Spencer wrote:
Hi Frans,

Perhaps I misunderstood. He was talking about serializing a class,
but from what I gather it sounds like he just wants to serialize the
data. If you only serialize the data, you can't deserialize it back
to a class. But there are certainly times when it's useful to do what
you're describing. So, since you seem to have a better picture of
what he wants to do, I'll just leave it to you. :-)


heh :) I think his main confusion comes from the fact that in MFC you
also could implement serialization but that was solely about the data
and resulted in implementing datareader/writers so no class info ended
up in the output stream if you didn't want to. (if my rusty MFC memory
still functions correctly ;))

in .NET you either have to do manual writing/reading the data (which
is actually pretty straight forward in this case IMHO) or accept class
info in the output.

FB

--
------------------------------------------------------------------------
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#)
------------------------------------------------------------------------

Jun 28 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hs | last post by:
Hi I am serializing a dataset using a binary formatter as follows: IFormatter formater = new BinaryFormatter(); formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream .... DataSet...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
2
by: Dave Veeneman | last post by:
I'm working on a project where I have to persist data to a file, rather than to a database. Basically, I need to save the state of several classes, each of which will have a couple of dozen...
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
7
by: schoenfeld1 | last post by:
I've implemented IPC between two applications using named pipes and binary serialization, but have noticed that the binary formatter is rather slow. It seems that the binary formatter reflects...
0
by: Vince Filby | last post by:
Hi, We are working with distributing Lucene.net. We have Master Index Server which takes responsibility of distributing the index searching to multiple Index Servers by calling the remote...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
1
by: sandeepbhutani304 | last post by:
have 2 projects communicating each other with .NET remoting. But when I am trying to call these functions I am getting the error: The input stream is not a valid binary format. The starting...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.