gpt4 book ai didi

language-agnostic - 为什么不是每种类型的对象都可序列化?

转载 作者:行者123 更新时间:2023-12-04 02:42:51 25 4
gpt4 key购买 nike

为什么不是每种类型的对象都可以隐式序列化?

在我有限的理解中,对象不是简单地存储在堆上并且指向它们的指针在堆栈上吗?

您不应该能够以编程方式遍历它们,以通用格式存储它们并能够从那里重建它们吗?

最佳答案

某些对象封装了诸如文件指针或网络套接字之类的资源,当您序列化包含它们的对象时,这些资源无法反序列化为它们所处的状态。

Example: you shouldn't deserialize an object that serves as an authenticated database connection, because to do so, you'd need the serialized form to contain a plaintext password. This would not be a good practice, because someone might get a hold of the saved serialized form. You also have no idea when you deserialize that the database server is still running, can be accessed, the authentication credentials still valid, etc.

关于language-agnostic - 为什么不是每种类型的对象都可序列化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1309673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com