存储大量文本数据的最佳方式?
我计划构建一个我的新游戏加载的“数据文件”,该文件包含大量文本(我们正在谈论 300-400,甚至可能是双倍的段落)以及一些琐碎的数据。基本上,将这些数据存储在文件中的最佳方式是什么。 有一些要求:
- 向后/向前兼容(能够优雅地接受旧数据并识别新数据(
- 可加密(所以像 sqlite 这样的东西会很糟糕?))
- 轻量级且快速加载,
- 可能带有某种反腐败恢复扇区。
基本上,有什么适合我的需求吗?或者是“自己动手”的情况(两者都没有问题),我会推荐什么
。很多人将 XML 抛到了九霄云外(太“庞大”和复杂),正在考虑类似虚拟文件系统的东西,带有用于快速读取数据的“位置表”,
我很好奇其他程序员会做什么 。不得不说。
I am planning on building a 'data file' that my new game loads, this file contains a whole lot of text (we are talking about 300-400, maybe even double that, paragraphs) along with some trivial data. Basically, what would be the best way of storing this data in a file.
There are a few requirements:
- backward/forward compatible (be able to gracefully accept older data and recognize new data(
- encryptable (so something like sqlite would be bad?)
- lightweight and quick to load
- possibly with some sort of anti-corruption recovery sector.
Basically, is there anything out there that fits my needs? or is it going to be a 'roll-your-own' situation (no problem with either). If it's a roll-my-own, what would you recommend.
I pretty much threw XML out of the window (far too 'bulky' and complex), was thinking of something like a virtual file-system, with a 'location-table' for quick reading of the data.
I'm pretty curious what other programmers have to say.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很抱歉您抛弃了 XML。一旦你掌握了它的窍门,它就会变得非常容易使用,而且当你掌握了它之后,它就会成为你从一个工作到另一个工作的技能。
老实说,XML 就是我的做法。我在游戏中使用 Java,而不是 C#,但无论如何,所有任务文本和 NPC 交互都存储在 XML 中。
I'm sorry that you threw out XML. It's pretty easy to work with once you get the hang of it, and when you do it's a skill that carries with you from job to job.
Honestly, XML is how I would do it. I'm using Java for my game, not c#, but regardless, all the quest text and NPC interaction is stored in XML.
XML 和 JSON 都是非常好的数据存储格式,尽管 XML 对于某些应用程序来说可能更灵活,但对于其他应用程序来说就有些过头了。
只有当您大量手动编辑 XML 时,XML 才显得“庞大”;如果不压缩它,则 XML 会存储在磁盘上。它的 gzip 压缩效果非常好。
XML and JSON are both pretty good formats for storing data, although XML can be more flexible for some applications, and overkill for others.
XML is only 'bulky' if you're editing it by hand a lot and on disk if you're not compressing it. It gzips very well.
您对“大”XML 开销的看法有点错误。它没有您想象的那么大,但 XML 提供了很大的灵活性。看一下一些 XML 解析器——它们非常简单。
.NET XML 最佳实践
You're a bit wrong about 'large' XML overhead. It's no so large as you think while XML provides a great flexibility. Take a look at some XML parsers -- they're really simple.
.NET XML Best Practices