Responding to RAM availability in iOS

后端 未结 4 2044
[愿得一人]
[愿得一人] 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:41

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

    I've lifted the blog's code for convenience and posterity:

    #include 
    
    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 app that uses sysctl() in this manner. It is documented, but only for Mac OS X.

提交回复
热议问题