Accessing serialized objects randomly
1 posts in topic
Flat View  Flat View

Posted By:   Prameela_Nair
Posted On:   Monday, July 18, 2005 01:05 AM

Is there any way to access objects written to a file randomly. Serialization basically needs accessing objects in the same order as they are writeen. but i need to access object(s) in any order.
Any suggestions on how to do so?

Re: Accessing serialized objects randomly

Posted By:   Parminder_Singh  
Posted On:   Tuesday, July 19, 2005 01:56 AM

For Random access what you can do is maintain two files. Each time you serialize an object to a file, get the size and persist this size and the object id to another file (call this the "size" file).

When you wish to modify an object, read the size of each object from the "size" file, calculate the bytes you need to skip and the bytes that you need to read. This should do for you. Before adding/deleting use the same logic and update the "size" file.

If the number of objects you are playing with is not large, what you can do is, add ur objects to a list and serizlize this list. Whenever you want to modify an object, read this list, modify the object and serialize the list again.
About | Sitemap | Contact