467,895 Members | 1,382 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,895 developers. It's quick & easy.

Serializable, what and why?

Could someone help me understand 'Serializable'?

What is this 'Serializable' why do we need it and how do we use it? Any
link or simple example would be great.

May 1 '06 #1
  • viewed: 3041
Share:
6 Replies
DBC User,

Serialization is the act of being able to take an instance of an object
and save it in its current state to another storage medium. In .NET, this
is always a stream, but since streams can have different backings, the uses
for this mechanism are virtually limitless.

One use is in remoting situations. When you pass parameters to/from a
method that is being executed in an app domain outside of your own,
serialization is used to package the parameters into byte streams that can
be passed to the other app domain.

You can also save the stream to a file on disk, or in a database, and
then deserialize the instance later, continuing to use it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DBC User" <db*****@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
Could someone help me understand 'Serializable'?

What is this 'Serializable' why do we need it and how do we use it? Any
link or simple example would be great.

May 1 '06 #2
http://msdn.microsoft.com/msdnmag/issues/02/04/net/ is probably a good
introduction.

Cheers,

Greg
"DBC User" <db*****@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
Could someone help me understand 'Serializable'?

What is this 'Serializable' why do we need it and how do we use it? Any
link or simple example would be great.

May 1 '06 #3
Serialization just means to store an object as a byte stream. It will
typically be an XML text byte stream, or a binary byte stream. You need
this functionality to store an object in a file, or to send it over a
wire. An object that is "serializable" meets the criteria for being
serialized automatically into XML (typically meaning it has public
read/write properties, at least one empty constructor overload, and
perhaps a few others). In order to be serialized as XML you will lose
the methods, of course. XML serialization is typically used for data
container classes and collections. Binary serialization can preserve
the methods and private members, but people normally don't speak in
terms of binary serialization.

May 1 '06 #4
Thanks a bunch guys. Greg, the link is very good.

May 1 '06 #5
Eric,

See inline:
Serialization just means to store an object as a byte stream. It will
typically be an XML text byte stream, or a binary byte stream.
A byte stream is a byte stream, there isn't a different flavor to either
of them. How they are interpreted is a different thing. The SOAP formatter
serializes instances into SOAP messages, which ultimately can be stored as a
byte stream, while the binary formatter uses a much more compact
representation.
You need this functionality to store an object in a file, or to send it
over a
wire. An object that is "serializable" meets the criteria for being
serialized automatically into XML (typically meaning it has public
read/write properties, at least one empty constructor overload, and
perhaps a few others).
It is eligible to be serialized using the SOAP formatter (which produces
XML), but it does not automatically mean that you can use XML serialization.
In order to be serialized as XML you will lose the methods, of course.
XML serialization is typically used for data container classes and
collections.
Binary serialization can preserve
the methods and private members, but people normally don't speak in
terms of binary serialization.


This isn't true. When you serialize an instance of a type, the method
information is not stored. That is a part of the type itself, and there is
no reason to store it. Rather, just the field values are stored. Storing
the method information would mean you are storing code in some way, or local
variables, and that's not what happens. It would make no sense to do so.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
May 1 '06 #6
When I was talking about binary serialization I was thinking of Marshal
By Value in remoting, in which a complete object (including methods) is
serialized and sent over the wire. I guess this isn't a generalized
case of using a Binary Formatter. I not exactly sure how this is done -
I haven't used it myself.

May 3 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Magnus Byne | last post: by
reply views Thread by xmail123 | last post: by
8 posts views Thread by xmail123 | last post: by
2 posts views Thread by John | last post: by
1 post views Thread by cpnet | last post: by
3 posts views Thread by Techno_Dex | last post: by
8 posts views Thread by Techno_Dex | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.