将复杂对象集合连续序列化到文件
我正在开发一个记录复杂系统状态的应用程序。 我必须将这些状态记录到 xml 文件中(使用 xml 序列化)。 该文件用于重放记录的事件并对其进行分析。
上下文:
我的应用程序显示一组复杂的数据(我们称之为视图) 每个视图包含 1 个对象和 2 个对象集合(400 个项目,每个项目大约有 20 个属性)。
应用程序以固定间隔记录数据状态(2 条记录之间的时间可能从 5 秒到 60 分钟不等),所有记录都存储在 VIEWS 集合中,我们将此 VIEW 集合保存到跟踪文件中(使用 xmlserializer 和将我的对象集合序列化为文本编写器)
一切都很好,但是当文件达到大约 20 Mo 时,文件保存可能比 2 个记录事件之间的时间花费更多的时间(文件存储在网络上,有时我们有滞后),我们希望对此进行优化。
所以我的问题是:
是否有一种方法可以将对象附加到文件而无需加载和写入整个文件,或者有一种方法可以优化文件的序列化?
我们必须使用 xml 序列化,因为文件必须可供人类读取通过代码(反序列化)。
I'm working on an application that record the state of a compplex system.
I've to record these states to xml files (using xml serialisation).
This file is used to replay the recorded event and analyse it.
the context:
My application display a set of complex data (we called this a VIEW)
each view contains 1 object and 2 collections of objects (400 items each with about 20 properties).
The application record a state of the data at fixed interval (the time between 2 record may vary from 5 sec to 60 min), all records are stored in a VIEWS collection and we save this collection of VIEW to a trace file (using xmlserializer and serialise my object collection to a text writer)
All works well but when the file reach about 20 Mo, the file save can take more time than the time between 2 record event (file are stored on the network and sometime we have lags) and we wants to optimize this.
So my question is :
Is there a way to append an object to a file without have to load and write the entire file or a way to optimize the serialisation to file?
We have to use xml serialisation because the file must be readable by human & by code (deserialisation).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用数据库怎么样?这些东西是为了解决这样的问题:)如果你想手动完成,你将必须声明你自己的协议。一个原始的工作实现:
How about using a database? Those things are made to solve problems like these :) If you want to do it manually, you will have to declare your own protocol. A primitive working implementation: