Can I serialize two objects to one file?

  • Thread starter Thread starter Cip
  • Start date Start date
C

Cip

I have a question using Binary Serialization (not XML).

If I have two objects, A and B, can I serialize both of them to the
SAME file ?

I KNOW I can put objects A and B in a container class and just
serialize it, but that is NOT what I am asking.

In other words, I want to *independently* serialize two or more
objects to the same output file stream.

As well, I want to somehow deserialize each object separately.
(Instead of deserializing an entire File Stream at once, I want to
somehow specify what part of the File Stream I would like to
deserialize)

in pseudocode:

Object myObjA;
Object myObjB;

FILE = "test.bin"

Serialize(myObjA,FILE,ObjectIndex1)
Serialize(myObjB,FILE,ObjectIndex2)

//and then to deserialize only one of the "ObjectIndex" from the FILE
Object myObjC = Deserialize(FILE,ObjectIndex1)


Is that possible? how can I achieve that? any links?
Which NG should I post to?


You may be asking WHY I need to do this... well if I have a Collection
or an Array with 10,000,000, items I do not want to
serialize/deserialize all of it at once as it can take a while.

I would like to somehow organize the data in smaller chunks, so that I
will only serialize/deserialize the chunks that are needed by the
users. If I can work independently with many objects in one file then
I can achieve this.


Thanks a lot,
Cip
 
alize as many objects as you like to the same file in a sequence but you'll
have a job getting them out in anything other than the sequence they went in
at.

For example, if you serialize objects a,b and c you can only get b out by
first deserializing and discarding a.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*

The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*
 
There is the notion of "streams" within files... compound documents like word and excel use these. You *might* be able to take advantage of mechanisms like that. Do you care about the file(s) containing the stored items? Meaning, do you care about finding them and using them on other computers, etc., or are they strictly for the purpose of storing data short term

I've come up with a "storage manager" object model that uses Isolated Storage and/or Common Files storage locations that uses the notion of "bins" to store data. I never have to deal with the physical files, just keep track of "bin" names

for instance, in my job framework, I have a bin for which files have been processed today, I have a bin for what times each file has been processed, etc. Something like that might work out nicely for you too

If you simply MUST use a single file for multiple object serialization, as was mentioned, you're going to have an interesting time of plucking out mid-stream objects. Check in to Compound Documents and see if they'll help you.
 
Bob Powell said:
alize as many objects as you like to the same file in a sequence but you'll
have a job getting them out in anything other than the sequence they went in
at.

For example, if you serialize objects a,b and c you can only get b out by
first deserializing and discarding a.


Actually I think I found something that might work:

http://www.eztools-software.com/fr.asp?s=tools&l=/tools/ezstor/default.asp

Apparently its a tool that can store any number of binary objects in
ONE file. I can then deserialize each object individually. It is
primarily used to eliminate storing BLOB fields in databases, but I am
sure I can use it for my purpose.

This might be of help to others!
 
Back
Top