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

查看:15
本文介绍了响应 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 具有低分辨率屏幕;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.

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

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. 我已经在 SO 上搜索了与可用 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天全站免登陆