简体   繁体   English

我们可以给序列化对象分配名称吗?

[英]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). 我可以通过为每个对象分配一个唯一的字段,然后将其与该字段进行比较来做到这一点,但这将花费O(n)。

Is there any other way to fast access any particular object, serialized in a file of suppose 100 objects. 是否有其他方法可以快速访问任何特定对象(在假定有100个对象的文件中序列化)。

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. 如果确实需要单个文件,则可以将它们全部归档为ZIP文件,并让其为您处理索引功能。

Maybe it's overkill, but for that use case i would use a database. 也许这是矫kill过正,但是对于该用例,我将使用数据库。 Something like Berkeley DB sounds appropiate: 像Berkeley DB这样的东西听起来很合适:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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