iOS中的内存映射文件数量是否存在实际限制? [英] Is there a practical limit on the number of memory mapped files in iOS?

查看:392
本文介绍了iOS中的内存映射文件数量是否存在实际限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可能有数百个内存映射的应用程序,即 mmap(),在任何时间点打开的文件。

I have an application that can potentially have hundreds of memory mapped, i.e., mmap(), files opened at any point in time.

我正在寻找一些帮助,了解实际限制对打开的内存映射文件数量的影响是什么。

I'm looking for some help understanding what, if any, the practical limit is on the number of opened memory mapped files is.

我创建这些mmap文件,如:

I create these mmap files like:

void* map = mmap(0, *capacity, PROT_READ | PROT_WRITE, MAP_SHARED, file, 0);


推荐答案

iOS内核为每个进程分配大约700mb的虚拟内存。这将是你的限制。

iOS kernel allocates around 700mb of virtual memory per process. So that will be your limit.

当你触摸映射数据时,内核将数据从虚拟内存中分配到RAM中,因此你对RAM的限制会有所不同。当RAM本身填满时,iphone 4上大约40mb,取决于其他应用程序连接多少RAM,并且您请求更多映射数据,内核将需要从RAM中分页数据并将其替换为所请求的数据将其分配到RAM中。

The limit you have on RAM will differ as the kernel pages data into RAM from virtual memory as you touch on the mapped data. When the RAM itself fills up, around 40mb on the iphone 4, depending on how much RAM is wired by other applications, and you request more mapped data, the kernel will need to page data out of RAM and replace it with the requested data by paging it into RAM.

另外要记住的是,如果你使用 PROT_READ | PROT_WRITE 然后您允许将数据写入映射文件。如果您决定将数据写入映射文件,这将影响700mb的已分配空间。

Another thing to remember is that if you use PROT_READ | PROT_WRITE then you are allowing data to be written to the mapped file. This will then impact the 700mb of allocated space if you decide to write data to the mapped file.

因此虚拟内存的限制为700mb,无论您是否映射一个文件500mb然后再写200mb的数据,或者你有例如您刚刚阅读的10 X 70mb映射文件。

So the limit is 700mb for virtual memory, whether you map one file of 500mb and then write another 200mb of data to it, or if you have e.g. 10 X 70mb mapped files that you just read.

最后一件事是,只要您使用 mmap()。

One last thing is that you can release the opened file that was the source of the mapped data as soon as you have received a successfully mapped file using mmap().

希望这会有所帮助。

其他信息:


  • 关于iphone的700mb虚拟内存和大约40mb RAM,这来自使用乐器进行分析。

  • Regarding the iphone's 700mb virtual memory and around 40mb RAM, this comes from doing profiling using instruments.

关于系统内存管理的实际工作方式。阅读虚拟内存
关于这在iOS上如何运作。阅读虚拟内存专注于OS X,但提到iOS上的差异

Regarding the actual workings of a systems memory management. Read up on virtual memory Regarding how this works on iOS. Read the apple docs on virtual memory which focuses on OS X, but mentions differences on iOS

这篇关于iOS中的内存映射文件数量是否存在实际限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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