开发者

How many objects can an nsarray hold? [duplicate]

This question already has answers here: 开发者_JS百科 Closed 11 years ago.

Possible Duplicate:

Maximum amount of objects in NSArray

I was just wondering how many objects I can put into an NSArray, because I need to find something that functions like an array, but I need to hold a lot of data (between 900 and 1200 strings). I was thinking about using an NSDictionary to hold the data, but it doesn't seem to fit the bill. Do you think an NSArray will hold that many objects, or should I use an NSDictionary?


Technically, NSArray can hold up to NSUIntegerMax objects (this is the largest value that can be returned from count). On a 32-bit system like the iPhone, that is a little over 4 billion. On a 64-bit system like most Macs, it is many orders of magnitude higher. By the time you even need to think about running out of room in an NSArray, you're going to have other scaling problems to deal with first, like the fact that 4 billion four-character strings will take up something like 16 GB of memory.

NSArray has two internal implementations for differently sized arrays — 1200 items would still be well within the "small array" implementation.


How much memory do you have?

There is no practical upper limit other than the number of bits it takes to hold all that data. 1200 items is fine. But if those items are each 10 thousand word strings, you may start needing too much memory to hold them all.


You can store an unlimited number of objects in an NSArray until you run out of memory. 900-1200 strings is not a large number, but it obviously depends on the length of each string. Do you know in advance whether they will be long?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜