This seems like a LOT of memory to put on the stack. I don't know the types of your arrays, but assuming they're ints, the colorValue array is 7,680,000 bytes wide, and labelValue is 1,920,000, for a total of 9,600,000 bytes on the stack. Most of the time this will be much larger than will be allowed for the stack, leading to your problem. This much data should be placed on the heap. You could do this in various ways, but the most common would be to allocate:
or
Code:
height*width*4*sizeof(int)
bytes on the heap using malloc. The (void *) returned could be cast to an (int *), and assigned to an int * variable you have on the stack (using a nice, trim 4 or 8 bytes (sizeof(void *)) depending on your platform). It would take a lot more work to be able to handily treat this as a 3-dimensional array, because you would need a lot more pointers at each dimension. You could use multiple "indicies" into this memory that you invent and track, but to actually be able to say myArr[x][y][z] would take a herculean effort.
In the last thread I suggested this, but I will again... why not use the dynamic data structures already available for this purpose? You could easily make a class that is a simple int wrapper (instead of using NSNumber), and build a:
Code:
NSMutableArray of
NSMutableArray of
NSMutableArray of
intWrapper which contains an
int
(That's not code, not sure if quote maintains formatting)
You would access it as:
Code:
rPart = [[[[colorValue objectAtIndex:x] objectAtIndex:y] objectAtIndex:0] intValue];
gPart = [[[[colorValue objectAtIndex:x] objectAtIndex:y] objectAtIndex:1] intValue];
bPart = [[[[colorValue objectAtIndex:x] objectAtIndex:y] objectAtIndex:2] intValue];
alphaPart = [[[[colorValue objectAtIndex:x] objectAtIndex:y] objectAtIndex:3] intValue];
Though this would give you 96-bit colorspace, which is probably overkill, but it's just for example's sake. You could also have a method that does all of that for you:
Code:
-(int) valueFrom:(NSArray *)valList Xpos:(int)x Ypos:(int)y Zpos:(int)z {
return [[[[valList objectAtIndex:x] objectAtIndex: y] objectAtIndex:z] intValue];
}
then you could call it as:
Code:
int rValue = [self valueFrom:colorList Xpos:x YPos:y Zpos:0];
The setup of this would require a bit of work, but it wouldn't be too bad (not as bad as a C-means of trying to make something you can get to with [][][]):
Code:
NSMutableArray *colorList = [[NSMutableArray alloc] init];
for(int x=0;x<height;x++){
[colorList addObject:[[NSMutableArray alloc] init]];
for(int y=0;y<width;y++) {
[[colorList objectAtIndex:x] addObject:[[NSMutableArray alloc] init]];
for(int z=0;z<4;z++) {
[[[colorList objectAtIndex:x] objectAtIndex:y] addObject:[NSNumber initWithInt:0]];
}
}
}
This should be treated as pseduocode, even though i tried to write correct Objective-C. I am not at a mac, and don't have an objective-C environment set up here.
-Lee