iOS 内存分配 - 应用程序可以使用多少内存?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用内存<您的设备内存容量
用户使用此工具测试发现的结果列表:
1 https://stackoverflow.com/a/5887783/5181636
2 https: //stackoverflow.com/a/15200855/5181636
可以在此找到更多信息问题。
You can use memory < your device ram capacity
List of results found by users testing with this tool:
1 https://stackoverflow.com/a/5887783/5181636
2 https://stackoverflow.com/a/15200855/5181636
More information can be found on this question.
来自单独内存分配的块不是连续分配的(单独调用 alloc、malloc、new 等)。否则,它们将被连续分配(来自对 malloc 的同一调用,例如 new float[30])。根据 Apple 的说法,当您使用超过 20MB 的 RAM 时,您的应用程序可能会因内存使用而被关闭。但实际上,您可以获得大约...
如果您确实“需要”那么多内存用于移动应用程序,那么您确实应该将数据保存到临时文件中并对其进行处理。一个简单的方法是使用内存映射文件。
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...
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.
在底层,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)
目前,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.
我不知道应用程序内存使用限制是否为 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.