Reputation: 118
A quick question that I really need answered:
Which uses more memory?
A NSMutableArray
with a million objects OR a million NSMutableArrays
with one object?
Will there even be a difference?
Upvotes: 2
Views: 60
Reputation: 104698
A million NSMutableArrays with one object would consume more memory.
Suppose a basic NSMutableArray implementation which has a pointer and a size for its elements:
isa
, another 4 to 8 bytesNow this is not necessarily exactly how NSMutableArray is implemented, but it gives you an idea of memory cost for each instance in a general purpose implementation.
So would you rather take the sum of all those parts and:
sizeof(int*)
That should give you an idea that 1M arrays will consume much more memory. Of course, you can test this using Instruments if you need real numbers.
Upvotes: 1