Currently, I have a need to store a potentially large amount of data (as doubles) in memory. I had originally created a NSObject container to store the data and added those to a NSMutableArray. However, this meant creating potentially thousands (or even hundreds of thousands) of NSObjects, the allocation of which was slowing everything down a lot. Moreover, all of those objects were eating up more memory than I'd like. This same data can be "easily" represented by a 3 dimensional c array to the effect of:
double data[fieldCount][dataAggregateCount][recordCount];
//Aggregate count is actually a static 6 at the moment, so it could be initialized:
double data[fieldCount][6][recordCount];
However, I can't really store that as an instance variable (that I know of). At present I do this:
@implementation MyClass{
double *_data;
}
And then malloc the data:
_data = malloc(sizeof(double) * fieldCount * 6 * recordCount);
However, to access the data, I've gotta do some particularly verbose math:
double value = _data[x + (y * fieldCount) + (z * fieldCount * aggregateCount)];
What I really want is to access the data like so: _data[x][y][z] but, of course, the compiler bitterly complains about that sort of notation on a double *.
Am I being unreasonable to expect I could store a variable multidimensional c-array as an instance variable without resorting to a continuous chunk of memory and manual offset calculations?
NSNumberobjects takes a whole lot longer thanmalloc(sizeOf(double) * 100000). WhileNSNumbercan alloc on the stack (using that neat pointer storage trick), it's unlikely to with the numbers I'm dealing with. Thus, I'm alloc'ing 100,000 NSObjects. I'm trying to avoid this.