Reputation: 3152
I need to store up to 1.000.000 double values in different arrays (during calculation run). So far I'm using an NSMutableArray
but it looks like the memory usage is huge. One idea is to use an c-array in order to avoid the storage of objects in the NSMutableArray
. Is there a way to roughly estimate the memory usage of an NSMutableArray vs. and c-array? (I could not find any information about the size of an NSNumber
-object vs. an primitive like double or float).
Thanks.
Upvotes: 1
Views: 553
Reputation: 130102
It's pretty clear that the memory consumption of NSArray
will be bigger than of a raw C array.
How big the difference will be? Well, for every value in a NSArray
, every primitive double
has to be wrapped by a NSNumber
so at least 20 B added for every value, probably a bit more.
One estimate can be found here: Memory size of classes in Objective-C
Anyway, storing 1 000 000 values in memory is always a bit strange. Maybe it would be better to store them in a file and then load them when needed (e.g. using a memory mapped file).
Upvotes: 5