iOS 内存分配 - 应用程序可以使用多少内存?

发布于 2024-11-08 04:44:18 字数 144 浏览 0 评论 0原文

iO 在内存管理中使用非连续还是连续分配?假设如果用户分配超过 128 MB,应用程序会被关闭吗?或者内存将由 iOS 管理,就好像用户分配内存并错过了 Deallocate 方法中的释放一样?使用明确定义的数据结构分配,是否可以在应用程序中使用超过 120 MB 的空间?

Does iOs use non-contiguous or contiguous allocation in memory management? suppose if user allocates more than 128 MB, Will the App be closed? or Memory will be managed by iOS as if user allocates memory and misses deallocate in Deallocate method? is it possible to use more than 120 MB in application using well-defined data structure allocation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

感情洁癖 2024-11-15 04:44:18

您可以使用内存<您的设备内存容量

(例如,您使用 40 Mb 的 RAM,然后再分配 80 Mb 的内存用于
一些简短的计算)。在这种情况下,iOS 会杀死你的应用程序
立即。1

用户使用此工具测试发现的结果列表:

设备:(崩溃次数/总数/占总数百分比)2

  • iPad1:127MB/256MB/49%
  • iPad2:275MB/512MB/53%
  • iPad3:645MB/1024MB/62%
  • iPad4:585MB/1024MB/57% (iOS 8.1)
  • 第一代 iPad Mini:297MB/512MB/58%
  • iPad Mini 视网膜显示屏:696MB/1024MB/68% (iOS 7.1)
  • iPad Air:697MB/1024MB/68%
  • iPad Air 2:1195MB/2048MB/58% (iOS 8.x)
  • iPad Pro 12.9:3064MB/3981MB/77% (iOS 9.3.2)
  • iPad Pro 9.7 英寸:1395MB/1971MB/71%(iOS 10.0.2 (14A456))
  • iPod touch 第 4 代:130MB/256MB/51% (iOS 6.1.1)
  • 第五代 iPod touch:286MB/512MB/56% (iOS 7.0)
  • iPhone4:325MB/512MB/63%
  • iPhone4S:286MB/512MB/56%
  • iPhone5:645MB/1024MB/62%
  • iPhone5S:646MB/1024MB/63%
  • iPhone6:645MB/1024MB/62% (iOS 8.x)
  • iPhone6+:645MB/1024MB/62% (iOS 8.x)
  • iPhone6s:1396MB/2048MB/68% (iOS 9.2)
  • iPhone6s+:1195MB/2048MB/58%(理论值,未经测试)
  • iPhoneSE:1395MB/2048MB/69% (iOS 9.3)
  • iPhone 6s+:1392MB/2048MB/68% (iOS 10.2.1)
  • iPhone 7+:2040MB/3072MB/66% (iOS 10.2.1)
  • iPhone X:1392/2785/50% (iOS 11.2.1)

1 https://stackoverflow.com/a/5887783/5181636

2 https: //stackoverflow.com/a/15200855/5181636

可以在此找到更多信息问题

You can use memory < your device ram capacity

(e.g. you're using 40 Mb of RAM, and then allocating 80 Mb's more for
some short computation). In this case iOS would kill your application
immediately.1

List of results found by users testing with this tool:

device: (crash amount/total amount/percentage of total)2

  • iPad1: 127MB/256MB/49%
  • iPad2: 275MB/512MB/53%
  • iPad3: 645MB/1024MB/62%
  • iPad4: 585MB/1024MB/57% (iOS 8.1)
  • iPad Mini 1st Generation: 297MB/512MB/58%
  • iPad Mini retina: 696MB/1024MB/68% (iOS 7.1)
  • iPad Air: 697MB/1024MB/68%
  • iPad Air 2: 1195MB/2048MB/58% (iOS 8.x)
  • iPad Pro 12.9: 3064MB/3981MB/77% (iOS 9.3.2)
  • iPad Pro 9.7": 1395MB/1971MB/71% (iOS 10.0.2 (14A456))
  • iPod touch 4th gen: 130MB/256MB/51% (iOS 6.1.1)
  • iPod touch 5th gen: 286MB/512MB/56% (iOS 7.0)
  • iPhone4: 325MB/512MB/63%
  • iPhone4S: 286MB/512MB/56%
  • iPhone5: 645MB/1024MB/62%
  • iPhone5S: 646MB/1024MB/63%
  • iPhone6: 645MB/1024MB/62% (iOS 8.x)
  • iPhone6+: 645MB/1024MB/62% (iOS 8.x)
  • iPhone6s: 1396MB/2048MB/68% (iOS 9.2)
  • iPhone6s+: 1195MB/2048MB/58% (theoretical, untested)
  • iPhoneSE: 1395MB/2048MB/69% (iOS 9.3)
  • iPhone 6s+: 1392MB/2048MB/ 68% (iOS 10.2.1)
  • iPhone 7+: 2040MB/3072MB/66% (iOS 10.2.1)
  • iPhone X: 1392/2785/50% (iOS 11.2.1)

1 https://stackoverflow.com/a/5887783/5181636

2 https://stackoverflow.com/a/15200855/5181636

More information can be found on this question.

美胚控场 2024-11-15 04:44:18

来自单独内存分配的块不是连续分配的(单独调用 alloc、malloc、new 等)。否则,它们将被连续分配(来自对 malloc 的同一调用,例如 new float[30])。根据 Apple 的说法,当您使用超过 20MB 的 RAM 时,您的应用程序可能会因内存使用而被关闭。但实际上,您可以获得大约...

  • iPad 2 上的 260 MB 内存(感谢 RobCroll)
  • 总共 512 Mb 内存的设备(iPhone 4、iPod touch 4g)
  • 上有 170-180MB 内存 40-80MB 内存具有 256 MB RAM 的设备(iPad、iPhone 3gs、iPod touch 3g)
  • 只有 128MB 的设备上具有 25 MB内存(iPhone 3g、iPhone 2g、iPod touch 1g-2g)

如果您确实“需要”那么多内存用于移动应用程序,那么您确实应该将数据保存到临时文件中并对其进行处理。一个简单的方法是使用内存映射文件。

Blocks from separate memory allocations are not allocated contiguously (separate calls to alloc, malloc, new, etc.). Otherwise they are allocated contiguously(from the same call to malloc, ex. new float[30]). According to Apple your app risks being shut down for memory usage when you use more than 20mb of ram. In practice however, you can get to about...

  • 260 MB of ram on iPad 2 (Thanks RobCroll)
  • 170-180MB of ram on devices with 512 Mb of ram total (iPhone 4, iPod touch 4g)
  • 40-80MB of ram on devices that have 256 MB of ram (iPad, iPhone 3gs, iPod touch 3g)
  • 25 MB on device with only 128MB of ram (IPhone 3g, iPhone 2g, iPod touch 1g-2g)

If you really "need" that much ram for a mobile application, you should really save the data to a temp file and do your processing on that. An easy way to do that is by using memory mapped files.

忆梦 2024-11-15 04:44:18

在底层,iOS 使用 malloc 和朋友为每个对象分配内存,所以返回的内存确实是连续的。如果您尝试分配超过可用的连续内存,则 malloc 调用将返回 NULL(如果未正确检查,在尝试访问空指针时可能会失败)

Under the hood iOS uses malloc and friends to allocate memory for every object, so yes the memory returned is indeed contiguous. If you try to allocate more than available contiguous memory the malloc call will return NULL (and probably something else will fail when trying to access a null pointer if not properly checked)

意犹 2024-11-15 04:44:18

目前,iOS 中的内存管理对应用程序没有明确的内存限制。
但是当 iOS 告诉你的应用程序立即释放内存或者它将被关闭时,你可以处理这种情况。

响应 iOS 中的低内存警告

128MB 对于 iOS 来说是一个相当大的内存块。如果您尝试分配超过内存限制,应用程序将在没有任何通知的情况下关闭。

Currently memory management in iOS works without clear memory limit for an application.
But you can handle the situation when iOS tells your app to release memory immediately or it will be closed.

Responding to Low-Memory Warnings in iOS

128MB is quite a big memory block for iOS. in case if you will try to allocate over memory limit an application will be closed without any notifications.

自由如风 2024-11-15 04:44:18

我不知道应用程序内存使用限制是否为 128 MB。但如果您消耗更多内存,您的应用程序将收到内存警告。如果您处理它们并清除缓存和稍后可以创建的其他对象,您的应用程序将不会退出。如果您忽略它们,您的应用程序将退出。

I dont know if app Memory usage limit is 128 MB or not. But if you consume more memory your application would receive memory warnings. If you handle them and clear cache and other objects that you can create at a later time, your application would not quit. If you ignore them, your application would quit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文