Solved

C# momentos for object serialization?

Posted on 2004-08-16
4
247 Views
Last Modified: 2008-03-10
I've been reading a book on C#.

When it talks about struct  (value type)  vs   class (reference type) it says:

"structs are best used for simple data types or momentos for object serialization and object state."

I don't understand the usage of "momentos" here, nor do I understand object serialization and object state.

Can someone enlighten me?
0
Comment
Question by:knowlton
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 11814724
knowlton this explains the pattern which .net uses for serialization oddly enough named the momento pattern and explains what exactly a momento is http://www.ondotnet.com/pub/a/dotnet/2002/09/09/memento.html
0
 
LVL 5

Author Comment

by:knowlton
ID: 11815429
Greg:

Perfect!

Any anecdotes you can provide me regarding actual usage (by you)?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11815538
my guidelines have always been ...

1) you want deep copy behavior implicitly (valye type)
2) you are using many times over in a local context example
3) when you are not copying it around a whole bunch
4) when you are not boxing/unboxing

as for using a momento ...

lets say I have a form ... (btw this is a PERFECT example) ...

lets say it has 30 fields on it that are adjustable by the user control locations etc ...

I cannot serializae the form for various reasons

What I do is implement ISerializable and serialize out an object that contains the 30 fields ... then on deserialization I use those 30 fields to set the value (the object itself only existed for a moment ... just to copy (hence a momento))

Another reason why the above is a great example is that in order to really serialize the form I would need to serialize hundreds, maybe thousands of values when in actuality I only needed 30 as the rest will come up programatically, thus I have reduced my serialization size.

0
 
LVL 5

Author Comment

by:knowlton
ID: 11816163
Cool.

This is way over my head right now....but I'm glad to see there are some practical applications to this concept.

Tom
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now