对象序列化的实际用途?

发布于 2024-09-04 04:47:10 字数 109 浏览 2 评论 0原文

您从事过多少个使用对象序列化的软件项目?我个人从未遇到过使用对象序列化的场景。我能想到的一个用例是,服务器软件将对象存储到磁盘以节省内存。是否有其他类型的软件需要对象序列化,或者比数据库更喜欢对象序列化?

How many software projects have you worked on used object serialization? I personally never came across a scenario where object serialization was used. One use case i can think of is, a server software storing objects to disk to save memory. Are there other types of software where object serialization is essential or preferred over a database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

铁轨上的流浪者 2024-09-11 04:47:10

我在很多项目中都使用了对象序列化。有时我们用它来本地存储计算机特定的设置。我还使用 XML 序列化来简化 XML 文档的交互和生成。它在通信协议中也非常有益。在一端序列化并在另一端重新膨胀。

I've used object serialization in a lot of my projects. Sometimes we use it to store computer-specific settings locally. I have also used XML serialization to simplify interaction and generation of XML documents. It is also very beneficial in communication protocols. Serialize on one end and re-inflate on the other end.

若相惜即相离 2024-09-11 04:47:10

将对象转换为 XML 或 JSON 是一种在 Web 上很常见的序列化形式。我还参与过一个项目,其中在一个应用程序中创建对象并将其序列化为二进制文件,然后导入到另一个自定义应用程序中(尽管这很脆弱,因为它使用 C# 并且序列化在过去的 .NET 框架版本之间已被破坏) )。此外,具有复杂结构的应用程序设置可能有助于序列化。我还认为远程 API 使用序列化进行通信。基本上,序列化通常只是存储对象状态的一种方式,并且有许多不同的用途。

Well, converting objects to XML or JSON is a form of serialization that is quite common on the web. I've also worked on a project where objects were created and serialized to a binary file in one application and then imported into another custom application (though that's fragile since it uses C# and serialization has broken in the past between versions of the .NET framework). Also, application settings that have a complex structure may be useful to serialize. I also think remoting APIs use serialization to communicate. Basically, serialization in general is simply a way to store the states of your objects, and this has many different uses.

千里故人稀 2024-09-11 04:47:10

以下是我能想到的一些用途:

  1. 通过网络发送对象,最常见的示例是跨集群序列化对象 序列
  2. 化对象以进行(某种)缓存,即将状态保存在文件中并稍后读回
  3. 序列化被动/巨大将数据保存到文件中,以最大限度地减少内存消耗,并在需要时将其读回。

Here are few uses I can think of :

  1. Send an object across network, the most common example is serializing objects across a cluster
  2. Serialize object for (sort of) caching, ie save the state in a file and read it back later
  3. Serialize passive/huge data to a file to minimize the memory consumption and read it back whenever required.
阳光下慵懒的猫 2024-09-11 04:47:10

我使用序列化通过 TCP 套接字传递对象。您将 XmlSerializers 放在任一侧,它会将您的数据解析为随时可用的对象。如果您做一些基础工作,您就可以得到它,这样您基本上就可以来回传递对象,并且它使套接字通信变得非常容易,将其简化为 socket.Send(myObject);socket.Send(myObject);代码>.

I'm using serialization to pass objects across a TCP socket. You put XmlSerializers on either side, and it parses your data into readily available objects. If you do a little ground work, you can get it so that you're basically passing objects back and forth, and it makes socket communication extremely easy, reducing it to nothing more than socket.Send(myObject);.

櫻之舞 2024-09-11 04:47:10

进程间通信是一个大问题。

Interprocess communication is a biggie.

姜生凉生 2024-09-11 04:47:10

你可以结合 db 和序列化。 f. 前。当您必须将具有大量属性的对象(通常是动态的,即一个对象属性集将与另一个对象属性集不同)存储到关系数据库,并且您不想为每个属性创建一个新列时

you can combine db & serialization. f.ex. when you have to store an object with a lot of attributes (often dynamic, i.e. one object attribute set will be different from another one) to the relational DB, and you don't want to create a new column per each attribute

烂柯人 2024-09-11 04:47:10

我们从一个每隔 15 分钟左右将所有数千个内存对象序列化到磁盘的系统开始。当开始花费太长时间时,我们切换到将对象保存到关系数据库和 pickle 文件中的混合模式(顺便说一句,这是一个 python 系统)。最终大部分数据存储在关系数据库中。有趣的是,系统的编写方式使得所有应用程序代码都不关心那里发生的事情。这一切都是使用 XP 和数千次自动化测试完成的。

We started out with a system that serialized all of the thousands of in-memory objects to disk every 15 minutes or so. When that started taking too long we switched over to a mixed mode of saving the objects into a relational db and pickle file (this was a python system btw). Eventually the majority of the data was stored in a relational database. Interestingly, the system was written in such a way that all of the application code couldn't care less what was going on down there. It was all done using XP and thousands of automated tests.

望笑 2024-09-11 04:47:10

当用户调用“保存”命令时,基于文档的应用程序(例如文字处理器和矢量图形编辑器)通常会将文档模型序列化到磁盘。在这些应用程序中,序列化通常优于复杂的数据库。

Document based applications such as word processors and vector graphics editors will often serialize the document model to disk when the user invokes the Save command. Serialization is often preferred over complex databases in these apps.

三人与歌 2024-09-11 04:47:10

每次您想要实现导入/导出功能时,使用序列化可以节省您的时间。

每次您需要导出系统数据、创建备份或存储某种设置时,您都可以使用序列化,只保存代表实际配置、数据或其他内容的对象的状态。

仅当您需要特定格式的导出/导入数据时,构建自定义解析器和导出器/导入器才有意义。

序列化也是防更改的。每当您更改交换功能中涉及的对象的格式时,它都会自动导出,并且您不必更改导出/导入部分背后的逻辑。

Using serialization saves you time each time you want to implement an import/export functionality.

Every time you need to export your system's data, create backups or store some kind of settings, you could use serialization instead and just save the state of the objects that represent the actual config, data or whatever else.

Only when you need a specific format of the exported/imported data, there is a sense in building a custom parser and exporter/importer.

Serialization is also change-proof. Whenever you change the format of the object that is involved in the exchange functionality, it is automatically exportable and you don't have to change the logic behind your export/import parts.

醉生梦死 2024-09-11 04:47:10

我们用它来进行备份和恢复。更新功能。它基本上是备份序列化的休眠对象,然后通过更新更改数据库模式,我们提供了一个帮助器类,将旧对象“转换”到新的数据库模式。这样我们就拥有了一个非常可靠的更新机制,不会轻易损坏,并且同时进行自动备份。

We used it for a backup & update functionality. It was basically serialized hibernate objects being backed up, then the DB schema is altered through the update and we delivered a helper class that "coverted" the old objects to the new DB schema. This way we had a pretty solid update mechanism that wouldnt break easily and does an automatic backup at the same time.

话少情深 2024-09-11 04:47:10

我在一个项目中大量使用了 XML 序列化。该技术用于持久化没有通用结构的数据库数据结构,因此无法直接存储数据。我还使用序列化来分离可以在运行时更改的应用程序设置。

I've used XML serialization heavily on one project. The technique was used to persist to database data structures that had no common structure, so the data couldn't be stored directly. I also used serialization to separate application settings that could be changed at runtime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文