R. Rahul
R. Rahul

Reputation: 1186

Can we assign name to the serialized objects?

During serializing objects, can we assign name to different objects? So, that on the time of reading objects, i can call any object by its name and later on can access its members.

I can do it by assigning a unique field to each object and later compare it against that field but that will cost - O(n).

Is there any other way to fast access any particular object, serialized in a file of suppose 100 objects.

Thanks you

Upvotes: 1

Views: 78

Answers (3)

gpeche
gpeche

Reputation: 22514

Maybe it's overkill, but for that use case i would use a database. Something like Berkeley DB sounds appropiate:

http://download.oracle.com/docs/cd/E17277_01/html/GettingStartedGuide/index.html

Upvotes: 0

erickson
erickson

Reputation: 269687

Why do all of the objects have to be in one stream? What if you just save each object in its own file and access the object by file name? If you really need a single file, you could archive them all in a ZIP file, and let it handle the indexing function for you.

Upvotes: 0

Noel M
Noel M

Reputation: 16116

Put them in a map and serialise the map instead?

Upvotes: 1

Related Questions