在运行之前在 iPhone 上创建并存储前缀树

发布于 2024-10-07 20:16:54 字数 243 浏览 0 评论 0原文

我目前正在为 iOS 制作一款文字游戏,加载时会读取大约 30000 个单词的文本文件,并将它们加载到前缀树中,以便在游戏过程中快速搜索。这效果很好,但加载和树构建过程明显增加了应用程序的启动时间几秒钟。目前我正在 iPhone 4 上进行测试,但我想在 3GS 早期型号上速度会慢很多。

有没有办法在编译时而不是在应用程序打开时创建此树?或者,不太理想的是,是否可以使用另一个程序预烘焙数据并将该文件添加到项目中,而不是在运行时执行此操作?我该怎么做呢?

I'm currently making a word game for iOS that, when loading, reads in a text file of around 30000 words and loads them into a prefix tree for quick searching during gameplay. This works well, but the loading and tree construction process adds a noticeable few seconds to the app's startup time. At the moment I'm testing on an iPhone 4, but I imagine it would be a good deal slower on a 3GS earlier models.

Is there a way to create this tree at compile time rather than when the app opens? Or, less ideally, would it be possible to prebake the data with another program and add that file to the project instead of doing it at runtime? How would I go about doing that?

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

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

发布评论

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

评论(2

梦中楼上月下 2024-10-14 20:16:54

我在我们开发的游戏中遇到了同样的问题,对于我们来说,使用带有单词的 SQLite DB 而不是内存中的树表现得更好。 DB 使用的空间比表示树的 plist 少,它不需要我们将其预加载到内存中,并且性能(查询有效单词时)大致相同。

I run into the same issue with a game we developed, and for us, it performed better to use a SQLite DB with the words instead of the in-memory tree. The DB used less space than the plist that represented the tree, it did not require us to preload it in memory, and the performance (when querying for a valid word) was about the same.

把人绕傻吧 2024-10-14 20:16:54

pgb的回答很好。如果您不想使用 SQLite,您可以将数据存储在 plist 中,并让 [NSDictionary DictionaryWithContentsOfFile:] 为您创建一棵树。

如果您确实选择将数据编译到程序中,则必须由基本类型(例如数字和字符)构建。然后,使用结构体和数组来定义结构体,并使用常量变量来存储数据。这是一个简单的例子,它只是一个字符串数组:

const char *words[] = {"Word1","Word2","Word3"};
const unsigned numWords = (sizeof(words) / sizeof(char*));

pgb's answer is good. If you do not want to use SQLite, you can store your data in a plist and have [NSDictionary dictionaryWithContentsOfFile:] create a tree for you.

If you do choose to have the data compiled into your program, it will have to be built of primitive types, such as numbers and characters. Then, use structures and arrays to define the structure, and use a constant variable to store the data. Here is a simple example which is just an array of character strings:

const char *words[] = {"Word1","Word2","Word3"};
const unsigned numWords = (sizeof(words) / sizeof(char*));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文