Responding to RAM availability in iOS

后端 未结 4 2033
[愿得一人]
[愿得一人] 2020-12-03 12:41

I have a texture-heavy OpenGL game that I\'d like to tune based on how much RAM the device has. The highest resolution textures I have work fine on an iPhone 4 or iPad2, but

4条回答
  •  时光取名叫无心
    2020-12-03 12:57

    The most important think you need to know for memory management in this case is wether to use High or low res textures. The simplest way I use is to check this

    CGFloat scale = [[UIScreen mainScreen] scale];
    if ((scale > 1.0) || (self.view.frame.size.width > 320)) {
            highRes = TRUE;
    }
    

    This works for all devices so far and should be future proof, newer devices will use the high res. You might also calculate right there the aspect ratio (helps later on ipad vs iphone)

    aspect = self.view.frame.size.width/self.view.frame.size.width
    

    Don't load highres first it kills your apps load time, on my 3G most of my startup is spent loading (even the low res) textures, just test for this right at the beginning and don't touch the highres stuff.

    On older devices the program will die without warning due to big textures, may have something to do with de debugger not being able to trap the video memory consumption and dying itself.

    For greater optimizations consider tinting you mipmaps to check the lowest texture size that's actually being used (only if your using 3D objects).

    Forget the video RAM size issue, memory is actually shared, so you're competing for system memory, on older devices you had a MB limit for use, but it's still system memory.

    About memory management, there are many ways to do it, the simplest should be mark the textures that are loaded, and textures that are needed, when a memory warning comes, dump the textures that are loaded but not needed...

提交回复
热议问题