简体   繁体   中英

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

将它们放在地图中,然后序列化地图?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM