Web Hosting Talk







View Full Version : Can objects (or classes instances) be saved ?


Lunar-Gang
04-18-2010, 08:22 PM
Hello Programmers !
Everybody knows how to save data to disk. Text/bin data can be saved from programs outputs to file streams or databases. Even webpages can use scripts like Javascript or VBscript to save data to your local machine. No matter what programming languages is used it can be done.
You can even dump arrays to files. but what about objects ? An object is an instance derived from a class, with a specific properties and methods. In my entire programming life I've never encountered a situation in wich you can save this instance to disk and retrieve it from disk !
Any body has an article or some resource of how to save objects to files ?

foobic
04-18-2010, 08:41 PM
http://en.wikipedia.org/wiki/Serialization

Lunar-Gang
04-18-2010, 10:45 PM
http://en.wikipedia.org/wiki/Serialization

What a helpful wiki :)

Lunar-Gang
04-19-2010, 06:49 PM
http://en.wikipedia.org/wiki/Serialization

But can objects restored to the exact status before saving using the serialization ?

Paul
04-19-2010, 07:53 PM
That is (one of) the point(s) of serialization.

What language is this for?

mattle
04-19-2010, 08:59 PM
But can objects restored to the exact status before saving using the serialization ?
Nope. For that, you need deserialization :)

Lunar-Gang
04-19-2010, 09:58 PM
What language is this for?

I am doing VB.Net can objects be serialized and deserialized safely with ?

mattle
04-20-2010, 08:04 AM
Yeah, .NET has a bunch of serialization classes. I prefer XMLSerializer (I think that's what it's called...it's been a while). IMHO, that's the best method for transportability of saved objects.

stahightech
04-21-2010, 06:56 PM
Hi,

With .NET the short answer is yes. However, you need to determine what kind of serialization you are looking to perform. The framework supports two types of serialization, Binary and XML serialization. With binary serialization the entire state of an object is preserved. On the other hand, XML serialization only saves the state of public properties and fields. See the following link for further clarification.

http://msdn.microsoft.com/en-us/library/7ay27kt9(VS.90).aspx

I hope this helps.

Regards

mattle
04-22-2010, 01:41 PM
XML serialization only saves the state of public properties and fields

Ah yes...forgot about that. Been over a year since my last .NET app :) Thanks for the refresher.