简体   繁体   English

在Java中序列化和反序列化LinkedList

[英]serialize and deserialize of linkedList in java

I serialized an object of user defined linked list class, as every node of that list get a memory location in heap, while deserializing if the memory location is already occupied for a particular node , for example 我序列化了用户定义的链表类的对象,因为该列表的每个节点都会在堆中获得一个内存位置,而反序列化某个特定节点是否已经占用了该内存位置,例如

在此处输入图片说明

if the memory of node 2 ie 200 is already occupied then how the node 1 knows about it and how the list deserialize? 如果节点2的内存(即200)已经被占用,那么节点1如何知道它以及列表如何反序列化? Or in java the memory allocation happens in some different way. 或者在Java中,内存分配以某种不同的方式发生。

JVM is responsible of object's management in memory. JVM负责内存中对象的管理。 After any GC is executed, objects allocated in memory can be moved, so the LinkedList doesn't actually points a fixed adress but reference 执行任何GC后,可以移动分配在内存中的对象,因此LinkedList实际上并不指向固定的地址,而是引用

Java has no pointers , only references to objects (safe references). Java没有指针 ,只有对象的引用(安全引用)。 A reference is similar to a pointer, because it points to a variable, an object, but you cannot view or edit the address memory of this reference (unlike C for example). 引用类似于指针,因为它指向变量(即对象),但是您无法查看或编辑此引用的地址存储器(例如,与C不同)。

Generally speaking you would not have to do any thing about about heap manually in Java. 一般来说,您无需在Java中手动处理堆。

Serialization should not effect heap unless you have some references to serialized node. 除非您对序列化节点有一些引用,否则序列化不会影响堆。

Interms to linked list two nodes don't need to know where other node is in memory. 链接列表两个节点的内部不需要知道其他节点在内存中的位置。

Hope this answers you question. 希望这能回答您的问题。

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

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