响应iOS中的RAM可用性 [英] Responding to RAM availability in iOS

查看:187
本文介绍了响应iOS中的RAM可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个质量很重的OpenGL游戏,我想根据设备有多少RAM进行调整。最高分辨率的纹理我在iPhone 4或iPad2上运行良好,但早期的设备在加载纹理的过程中崩溃。我有这些纹理的低分辨率版本,但我需要知道何时使用它们。

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 earlier devices crash in the middle of loading the textures. I have low-res versions of these textures, but I need to know when to use them.

我目前的策略是检测特定的旧设备(3GS具有低 - res屏幕; iPad没有摄像头),然后只加载IPad2及以上和iPhone 4及以上的高分辨率纹理 - 我想我需要为iPod touch做点什么。但我更倾向于使用特征检测而不是硬编码设备模型,因为模型检测对于API和硬件的未来变化是脆弱的。

My current tactic is to detect specific older devices (3GS has a low-res screen; iPad has no camera), then only load the hi-res textures for IPad2 and above and iPhone 4 and above — and I suppose I'll need to do something for the iPod touch. But I'd much rather use feature detection than hard-coding device models, since model detection is fragile against future changes to APIs and hardware.

我正在考虑的另一种可能性是先加载高分辨率纹理,然后在我得到低内存警告的时候放下并用lo-res替换它们。但是,我不确定我是否有机会回应;我注意到应用程序经常在调试控制台上出现任何通知之前就已经死了。

Another possibility I'm considering is to load the hi-res textures first, then drop and replace them with lo-res the moment I get a low memory warning. However, I'm not sure I'll get the chance to response; I've noticed that the app often dies before any notification appears on the debug console.

如何检测我运行的设备是否不足RAM加载我的纹理的高分辨率版本?

退一步,是否有一些我可以使用的特定于OpenGL纹理内存的自适应技术?

Taking a step back, is there some other adaptive technique I can use that's specific to OpenGL texture memory?

注意:


  1. 我一直在搜索和关闭因此,有关可用RAM检测的答案,但它们基本上建议分析内存使用情况并消除浪费(最大限度地减少临时工作的寿命,以及所有这些)。我尽可能多地完成了这项工作,并且我无法将高分辨率纹理压缩到旧设备中。

  1. I've searched on and off SO for answers related to available RAM detection, but they all basically advise profiling memory usage and eliminating waste (minimising the lifetime of temporaries, and all that guff). I've done as much of that as I can, and there is no way I am going to squeeze the hi-res textures into the older devices.

PVRTC不是一种选择。纹理包含片段着色器要使用的数据,并且必须以无损格式存储。

PVRTC isn't an option. The textures contain data to be used by fragment shaders and must be stored in a lossless format.


推荐答案

要获取设备的总(最大)物理RAM,请使用 [NSProcessInfo processInfo] .physicalMemory

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

参见文档

这篇关于响应iOS中的RAM可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆