问题描述
在Linux中,mremap函数用于重新映射使用mmap映射的内存.请帮助我澄清以下内容:
In Linux mremap function is used to remap the memory that was mapped using the mmap. please help me to clarify the following:
- 如果mremap函数失败,那么旧的映射内存的状态是什么?
- 如果mremap函数失败,是否需要调用函数munmap?
- 如果mremap函数成功,重新映射的内存中是否有先前的数据?
推荐答案
mremap尝试就地增加分配,但是如果不能增加当前区域的大小,则退回到分配新区域.
mremap attempts to increase the allocation in-place, but falls back to allocating a new region if it cannot increase the size of the current region.
-
如果mremap失败,则旧内存就可以了(就像重新分配一样).
If mremap fails, the old memory is just fine (just like realloc).
如果mremap失败,则无需进行munmap操作(至少是通过 this 调用).参见项目1.
If mremap fails, there's nothing to munmap (from this call, at least). See item 1.
如果mremap成功并且必须移动,则将旧内存复制到新内存中(旧munmap为您存储).如果mremap能够就地增加大小,则不会移动内存,也不会创建新的分配.
If mremap succeeds and has to move, the old memory is copied into the new (and the old one munmap'ped for you). If mremap is able to increase the size in-place, the memory is not moved and no new allocation is created.
这篇关于Linux中mremap函数的特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!