Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum amount of objects in NSArray

Tags:

cocoa

nsarray

What is the largest amount of objects I can put in my NSArray?

like image 540
Matt S. Avatar asked Jan 28 '10 15:01

Matt S.


People also ask

Can NSArray contain nil?

arrays can't contain nil. There is a special object, NSNull ( [NSNull null] ), that serves as a placeholder for nil.

Is NSArray ordered?

In Objective-C, arrays take the form of the NSArray class. An NSArray represents an ordered collection of objects. This distinction of being an ordered collection is what makes NSArray the go-to class that it is.

What is NSArray in Swift?

An object representing a static ordered collection, for use instead of an Array constant in cases that require reference semantics.

What is NSMutableArray?

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray . NSMutableArray is “toll-free bridged” with its Core Foundation counterpart, CFMutableArray .


4 Answers

Have you tried to find out? ;)

NSMutableArray * a = [[NSMutableArray alloc] init];
NSUInteger i = 0;
@try {
  while (1) {
     [a addObject:@"hi"];
     i++;
  }
} @catch (NSException * e) {
  NSLog(@"added %llu elements", i);
}
like image 181
Dave DeLong Avatar answered Sep 22 '22 20:09

Dave DeLong


The NSArray initWithCapacity method, takes an unsigned int as an argument. So whatever the maximum value of an unsigned int is on your platform may be the theoretical limit. However the actual limit is more likely to depend on the amount of memory you have available.

like image 37
Tom Jefferys Avatar answered Sep 25 '22 20:09

Tom Jefferys


In most cases concerning the upper limits of programming structures and the like:
"If you have to ask, you're probably doing it wrong" - TheDailyWTF.com

like image 35
Chris S Avatar answered Sep 21 '22 20:09

Chris S


Probably more than your RAM can handle.

like image 44
Eimantas Avatar answered Sep 21 '22 20:09

Eimantas