I'm just wondering if I'm doing this right...
Thanks,
Matt
Code:
- (void)saveDataIntoFile: (NSString*)name
{
//Create the 2000x2000x8 3D array
int width = 2000;
int height = 2000;
unsigned char*** pBytes = (unsigned char***)malloc(height*sizeof(**pBytes));
for (int i=0; i<height ; i++) {
pBytes[i] = (unsigned char**)malloc(width*sizeof(*pBytes));
for (int j=0; j<width; j++) {
pBytes[i][j] = (unsigned char*)malloc(8*sizeof(pBytes));
//Fill it with numbers
pBytes[i][j][0] = 0;
pBytes[i][j][1] = 0;
pBytes[i][j][2] = 0;
pBytes[i][j][3] = 0;
pBytes[i][j][4] = 0;
pBytes[i][j][5] = 0;
pBytes[i][j][6] = 0;
pBytes[i][j][7] = 0;
}
}
//Get path to save to
NSArray* splitPath = [[[NSBundle mainBundle] bundlePath] componentsSeparatedByString:@"/"];
NSString* path = @"";
for (int i = 0; i < [splitPath count]-1; i ++) {
path = [NSString stringWithFormat:@"%@/%@",path,[splitPath objectAtIndex:i]];
}
path = [NSString stringWithFormat:@"%@/%@",path,name];
//Save
NSData * pSaveData = [NSData dataWithBytes:pBytes length:width*height*8];
[pSaveData writeToFile:path atomically:YES];
[pSaveData release];
//Set free
for (int x = 0;x<width;x++){
for (int y = 0;y<height;y++){
free (pBytes[x][y]);
}
free (pBytes[x]);
}
free (pBytes);
}
Thanks,
Matt