[英]iOS how large can an NSSet/NSArray/NSDictionary be?
I feel I should first describe what I'm trying to do and then I'll ask my question(s). 我觉得我应该首先描述我想要做的事情,然后我会问我的问题。
I have a large amount of words (could be up to 5,000). 我有很多单词(最多可达5,000)。 I want to be able to display a random 3 of these words on the screen and when the user presses a button, it will display another 3 random words, but without duplicates (ie without presenting the same word to the user again).
我希望能够在屏幕上随机显示这些单词中的3个,当用户按下按钮时,它将显示另外3个随机单词,但没有重复(即不再向用户显示相同的单词)。 This will loop until a timer runs out.
这将循环直到计时器用完。
If the number of words was less, I'd just add these into an NSMutableSet, use -anyObject 3 times to get the words, and then remove the 3 words from the set each time so they're not used again when I next call -anyObject. 如果单词数量较少,我只需将它们添加到NSMutableSet中,使用-anyObject 3次获取单词,然后每次从集合中删除3个单词,这样下次调用时它们就不再使用了-anyObject。 The problem with this is I don't know if I can have a set with 5,000 NSStrings in it in iOS.
这个问题是我不知道我是否可以在iOS中拥有5,000个NSStrings。
So my questions are 所以我的问题是
Thanks in advance. 提前致谢。
Just to have an idea of which memory dimensions we are looking at: 5000 words of 8 letters each can be represented in UTF-8 (8 bits per letter) with 只是想知道我们正在查看哪些内存维度:每个8个字母的5000个单词可以用UTF-8(每个字母8位)表示
5000 * 8 * 8 = 320,000 bits = 40,000 bytes < 40 kB 5000 * 8 * 8 = 320,000位= 40,000字节<40 kB
Even if the overhead of a NSArray
, NSSet
etc. would double or triple that size (which it certainly doesn't), you'd be fine. 即使
NSArray
, NSSet
等的开销会增加一倍或三倍(当然不会),你也没关系。 An iPhone 4S has a RAM size of 1 GB, that's 1,048,576 kB, several ten thousand times the size of your object. iPhone 4S的RAM大小为1 GB,即1,048,576 kB,是对象大小的一万倍。 In short: Don't worry.
简而言之:别担心。
You could store your words in a text file, separated by spaces, and simply read them into an NSArray
with 您可以将单词存储在文本文件中,用空格分隔,然后将它们读入
NSArray
中
NSArray *testArray = [stringOfTextfileContent componentsSeparatedByString:@" "];
限制取决于您可用的内存量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.