iphone c++ 上的静态数据
我有国家/地区的数据,其中包括国家/地区的名称、人口、面积等...
存储它们的最佳方式是什么,我正在考虑头文件中的静态数组...?
我主要在 iPhone 上使用 C++ 来玩一些游戏,
我应该考虑其他选项,如 sqlite、plists、字典 ....?
I have data for countries which include Name, Population, Area etc for countries...
What is the best way to store them, I was thinking of static arrays in header files ...?
I am using c++ primarily for some game on iPhone
Should I consider other options like sqlite, plists, dictionaries ....?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于。如果数据永远不会改变,那么头文件中的静态数组可能是一个足够好的解决方案。问题是,如果有一天您确实想要更改数据,则必须重新编译应用程序,这可能不是您关心的问题。但这也可能是一个彻底的麻烦,特别是当您需要重复尝试某些数据的不同值时。
就我个人而言,我很想将这些数据存储在某种描述的外部文件中。 plist 可能非常适合此目的,但如果有大量非结构化数据,您可能会发现它们有点重量级。我经常使用简单的纯文本文件来存储某些类型的数据。
我怀疑 SQLite 可能完全是多余的,除非你的数据使用关系数据库构建是有意义的,或者需要由应用程序本身定期更改。
It depends. If the data is never going to change then static arrays in header files is probably a good enough solution. The problem is that if one day you do want to make a change to the data, you'll have to recompile your application, which might not be a concern for you. But it might also be a complete hassle, especially if you need to repeatedly try out different values for some of the data.
Personally I'd be tempted to store this data in an external file of some description. plists might be perfect for this, although if there's large amounts of unstructured data you might find them a bit heavyweight. I've often used simple plain text files for storing some types of data.
I suspect SQLite may be completely over the top, unless your data makes sense to be structured using a relational database, or needs to be changed by the app itself regularly.
避免代码中的数据。
Avoid data in code.