Response to RAM availability on iOS

I have a texture-heavy OpenGL game that I would like to configure based on how much RAM the device has. The highest resolution textures work fine on iPhone 4 or iPad2, but earlier devices crash in the middle of texture downloads. I have low resolution versions of these textures, but I need to know when to use them.

My current tactic is to detect certain old devices (3GS has a low resolution screen, iPad does not have a camera), then only hi-res textures are loaded for iPad2 and higher and iPhone 4 and higher - and I suppose you need something make for iPod touch. But I would rather use the object detection function than the hard-coding device models, since model detection is fragile with respect to future changes in the API and hardware.

Another possibility that I am considering is to first load the hi-res textures, and then reset and replace their lo-res the moment I get a low memory warning. However, I am not sure that I will have the opportunity to answer; I noticed that the application often dies before any notification appears on the debug console.

How to determine if the device I'm running on does not have enough RAM to load the hi-res versions of my textures?

Taking a step back, is there any other adaptive method that I can use for OpenGL texture memory?

Notes:

  • I searched and turned off SO for answers related to affordable RAM detection, but all of them basically advise profiling memory usage and eliminating waste (minimizing the time series lifetime and all this is guff). I did everything I could, and I'm not going to compress hi-res textures to older devices.

  • PVRTC is not an option. Textures contain data that will be used by flash shaders and must be stored in a lossless format.

+9
ios opengl-es textures feature-detection
Nov 07 2018-11-11T00:
source share
4 answers

To get the total (maximum) physical RAM of the device, use [NSProcessInfo processInfo].physicalMemory .

See Documentation .

+11
Oct 02 '13 at 15:46
source share

Common physical RAM is available through sysctl() , as described in this blog post and implemented as a nice clean API here (see the implementation of totalMemory in the corresponding .m file).

I took off the blog code for convenience and posterity:

 #include <sys/sysctl.h> size_t phys_mem() { int mib[] = { CTL_HW, HW_PHYSMEM }; size_t mem; size_t len = sizeof(mem); sysctl(mib, 2, &mem, &len, NULL, 0); return mem; } 

I don't know if Apple will approve an application that uses sysctl() in this way. It is documented, but only for Mac OS X.

+7
Nov 09 '11 at 21:55
source share

The most important thing you need to know to manage memory in this case is to use high or low resolution textures. The easiest 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 promising evidence, new devices will use high res. You can also calculate a directly proportional aspect ratio (ipad vs iphone will help later)

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

Don’t download highres in the first place, it kills the load time of your applications, in my 3G download most of my downloads load (even low resolution) textures, just check it right at the beginning and don’t touch the highres materials.

On older devices, the program will die without warning due to the large textures, it may have something to do with a debugger that is not able to capture video memory consumption and die.

For greater optimizations, consider tinting your mipmaps to check the lowest texture size that is actually used (only if you use 3D objects).

Forget about the problem with video memory size, the memory is actually shared, so you are competing for system memory, and on older devices you have an MB limit for use, but it is still system memory.

About memory management, there are many ways to do this: the simplest one should be marked with downloadable textures and textures, which are necessary when a memory warning appears, to unload downloadable but not needed textures ...

+2
Nov 09 2018-11-11T00:
source share

As far as I know, the 3 most important things you can do are

  • implement - (void)didReceiveMemoryWarning and respond when iOS sends warnings 1 and 2.
  • Profile code in the Tools, trying to find leaks and better use the best implementation methods.
  • Detecting device types and possibly using this information.
  • Use some form of texture compression, such as PVRTC, to save space.

I think you make the most of them. The fact is that it is not even known exactly how many iOS RAM devices. Apple does not publish technical specifications for iOS devices.

In addition, it cannot be assumed that only after, say, 100 mb of consumption, you will receive a warning about the opinion. The alerts provided by iOS vary depending on the current state of the device and other applications, as well as how much they consume. So it becomes difficult.

I can assume that 2 should read the sections - Recommendations for working with texture data and Customizing your OpenGL ES application

0
Nov 07 '11 at 4:21
source share



All Articles