There are lot of low-memory problems out there with Game Apps running on iPad devices. So I am thinking for my own game about the following solution: Before the App starts I alloc the required space and free it up immediately on start-up.
This seems to work very well, giving me more stability with memory allocation issues when the app is running. What do you think about it? Is it a good way to do this?
e.g:
{
size_t size = 30*MB;
NSLog(@"free up %u bytes", size);
size_t allocated = 0;
while(allocated < size && blocksCounter < MAX_BLOCKS) {
const size_t blockSize = 256*KB; // 256K blocks
blocks[blocksCounter] = malloc(blockSize);
if(blocks[blocksCounter]) {
bzero(blocks[blocksCounter], blockSize);
}
else {
NSLog(@"warning empty block at idx %d", blocksCounter);
}
blocksCounter++;
allocated += blockSize;
}
for(int i=blocksCounter-1; i>=0; i--) {
if(blocks[i]) {
free(blocks[i]);
}
}
blocksCounter = 0;
}