Handling low-memory start-up situations on iPad devices
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]) {
开发者_StackOverflow 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;
}
It is very bad practice. Because it is not a good user experience to force a low memory warning which leads to quitting the iPod app for example or stopping other running background applications such as skype or your navigation software.
I would watch your memory consumption more closely and work on that instead or using your elbows every time you start up your app. This is not good citizenship on iOS.
精彩评论