iOS 实际 RAM 和 ProcessInfo.processInfo.physicalMemory 稳定之间的差异?
iOS difference between actual RAM and ProcessInfo.processInfo.physicalMemory stable?
我正在开发一个需要在低内存设备上进行定制的应用程序。可用设备内存将在 swift 中给出:
ProcessInfo.processInfo.physicalMemory
例如:
- iPhone SE 给出 2009.5 MB (2048 MB RAM)
- iPhone 5 秒得到 1000.0 MB(1024 MB RAM)
- iPhone 6 给出 989.0 MB(1024 MB RAM)
- iPhone 6+ 给出 977.0 MB(1024 MB RAM)
- iPhone 4s 得到 504.95 MB (512 MB RAM)
根据我的理解,增量分配给 GPU 并取决于屏幕尺寸。
我可以相信给定的设备总是给我相同的 physicalMemory
金额吗?
(例如 iPhone 6 总是 989.0 MB)
看起来 physicalMemory
与 sysctl
中的 hw.physmem
(或其 macOS 等效项)相同。
我能找到的最佳描述来自 post comparing real/physical/user memory in FreeBSD:
The amount of "usable" RAM for the OS. This subtracts off
any spaces reserved by boot ROMs / BIOSes / what-have-you, and
in the case of (e.g.) FreeBSD-9 on amd64, the 1 TB direct-map
limit (which you must take care of manually with the loader's
hw.physmem setting).
This is what "phys mem" should be and mostly is. If you boot
a machine with 1.5 TB of RAM but the OS is limited to 1 TB,
hw.physmem should be 1 TB minus a bit for the BIOS, etc.
因此,它是设备上的实际内存减去非 iOS 的事物保留的内存。由于我们无法保证 Apple 不会更新这些系统中的任何一个,因此我们无法保证可用于应用程序的物理内存将是固定的。所以我不会硬编码任何这些神奇的数字。您可以查看通过系统调用检索“实际”内存大小,但您也可以只使用内存桶,因为您知道物理内存总是低于但接近实际内存:
enum MemorySize {
case low, medium, high
}
extension MemorySize {
static var current: MemorySize {
if ProcessInfo.processInfo.physicalMemory < 512 * 1024 * 1024 {
return .low
} else if ProcessInfo.processInfo.physicalMemory < 1024 * 1024 * 1024 {
return .medium
} else {
return .high
}
}
}
...
if MemorySize.current == .low { /* Use low memory setup */ }
我正在开发一个需要在低内存设备上进行定制的应用程序。可用设备内存将在 swift 中给出:
ProcessInfo.processInfo.physicalMemory
例如:
- iPhone SE 给出 2009.5 MB (2048 MB RAM)
- iPhone 5 秒得到 1000.0 MB(1024 MB RAM)
- iPhone 6 给出 989.0 MB(1024 MB RAM)
- iPhone 6+ 给出 977.0 MB(1024 MB RAM)
- iPhone 4s 得到 504.95 MB (512 MB RAM)
根据我的理解,增量分配给 GPU 并取决于屏幕尺寸。
我可以相信给定的设备总是给我相同的 physicalMemory
金额吗?
(例如 iPhone 6 总是 989.0 MB)
看起来 physicalMemory
与 sysctl
中的 hw.physmem
(或其 macOS 等效项)相同。
我能找到的最佳描述来自 post comparing real/physical/user memory in FreeBSD:
The amount of "usable" RAM for the OS. This subtracts off any spaces reserved by boot ROMs / BIOSes / what-have-you, and in the case of (e.g.) FreeBSD-9 on amd64, the 1 TB direct-map limit (which you must take care of manually with the loader's hw.physmem setting).
This is what "phys mem" should be and mostly is. If you boot a machine with 1.5 TB of RAM but the OS is limited to 1 TB, hw.physmem should be 1 TB minus a bit for the BIOS, etc.
因此,它是设备上的实际内存减去非 iOS 的事物保留的内存。由于我们无法保证 Apple 不会更新这些系统中的任何一个,因此我们无法保证可用于应用程序的物理内存将是固定的。所以我不会硬编码任何这些神奇的数字。您可以查看通过系统调用检索“实际”内存大小,但您也可以只使用内存桶,因为您知道物理内存总是低于但接近实际内存:
enum MemorySize {
case low, medium, high
}
extension MemorySize {
static var current: MemorySize {
if ProcessInfo.processInfo.physicalMemory < 512 * 1024 * 1024 {
return .low
} else if ProcessInfo.processInfo.physicalMemory < 1024 * 1024 * 1024 {
return .medium
} else {
return .high
}
}
}
...
if MemorySize.current == .low { /* Use low memory setup */ }