question about serialization

C

Casper

Hi,

i read several articles about serialization. I know now that it is a process
of converting an object into a stream of data so that it can be is easily
transmittable over the network or can be continued in a persistent storage
location.

Now i did some tests in order to understand it better:
I first executed the code below (this (summarized) code produces a virtual
simple shopping cart which is put in the Profile of the user) with the
attribute "<Serializable()>" and with what follows in web.config:

<profile><properties>
<add name="myCart" serializeAs="Binary" type="mai.eCommerce.elist"/>
</properties></profile>

After that, i executed it again without the attribute "<Serializable()>" and
without "serializeAs="Binary" from web.config.

I couldn't notice any difference (nor in table 'Profiles', nor in the table
'Orders' where the orders are put, nor in the shopping cart, nor in speed
nor in cache, nor in CPU ..).

So my question is:
------------------
what happens (physically on the client/server computer) in this present
application when using serialization what not (physically) happens when not
using it?

Thanks
Casper

<Serializable()> _
Public Class listitem
Private _description As String

Public Sub New()
End Sub

Public Property description() As String
Get
Return _description
End Get
Set(ByVal value As String)
_description = value
End Set
End Property
End Class
'--------------------------
<Serializable()> _
Public Class elist
.....
Public Sub New()
_items = New List(Of listitem)
End Sub
......
Public Sub Insert(ByVal Price As Decimal, ByVal description As String)
.....
End Class
 
B

bruce barker

the attribute Serializable just states the object can be serialized
using the default serialization logic (all properties are simple or have
implemented ISerializable).

you can set the attribute on classes that will not serialize and no
error will be thrown until runtime when a serialization is attempted and
fails (serialization finds a property of a type it can not serialize)

-- bruce (sqlwork.com)
 
C

Cor Ligthert [MVP]

Casper,
With the serializable tag before your class, your class becomes
serializable, withouth that it does not even do that.

Cor
 
C

Casper

Thanks for replying, but to be honest, i still don't know what really
happens (i mean physically on th computer) when using it and when not. Does
serialization (binary in this case) use a temporary storage, Cache, is the
way of storing profile data in the Profiles table of ASPNET.MDF else than
when not using it, ... such kind of things.
All i read about that is very abstract and that's why i ask for a pratical
explanation instead of a theoretical.
Thanks in advance.
 
B

bruce barker

serialization allows a class instance to write its values to a binary
stream of bytes. these byte an be deserialized to create a new class
instance with the same values. this is know as class persistence (google
this phrase).

thus if you store a class instance in a profile, the class is serialized
to bytes and the data written to a sqlserver table. when requested from
the profile, sql is read, and the bytes are used to create a new class
instance that has the same values of the old.

-- bruce (sqlwork.com)
 
C

Casper

Hi again.
I thought about your answers this (long) night, and maybe you will conclude
i will never understand it ...
but what's then the difference in my application between using
<serialisation> _ and not using it? In both cases, data comes into the sql
server table and in both cases, data are retrieved when needed.I tested it.
Is the difference the way data is put (and retrieved) into (from) the table
(with serialization: binary stream, without:?) Or is the attribute
<serialisation> _ just ignored when using Profiles, or ...?

In other words, why should i use <serialisation> _ if it also works without
it?
Thanks
 
C

Cor Ligthert [MVP]

Casper,

The word serialization is if you build your own class.

If the class is already serializable than there is no need to do something
extra.

Cor
 

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