c++ - Linux中mremap函数的特点

标签 c++ c linux

在 Linux 中,mremap 函数用于重新映射使用 mmap 映射的内存。请帮助我澄清以下内容:

  1. 如果 mremap 函数失败,旧映射内存的状态是什么?
  2. 如果mremap函数失败,是否需要调用munmap函数?
  3. 如果 mremap 函数成功,重映射内存中是否有以前的数据?

最佳答案

mremap 尝试就地增加分配,但如果它不能增加当前区域的大小,则回退到分配新区域。

mremap() expands (or shrinks) an existing memory mapping, potentially moving it at the same time (controlled by the flags argument and the available virtual address space). src

  1. 如果 mremap 失败,旧内存就好了(就像 realloc)。

  2. 如果 mremap 失败,则没有任何东西可以 munmap(至少从 this 调用)。请参阅第 1 项。

  3. 如果 mremap 成功并且必须移动,旧内存将被复制到新内存中(旧内存会为您进行 munmap)。如果 mremap 能够就地增加大小,则不会移动内存,也不会创建新分配。

关于c++ - Linux中mremap函数的特点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16080192/

相关文章:

linux - grep命令查找字符出现n次

c++ - 错误 : cannot convert ‘<lambda(double)>’ to ‘double (*)(double)’

c++ - 调整结构中的 vector 的大小

c++ - 从 Boost.Spirit.Qi 制作shared_ptr

C Language : trouble using enumerated variable and type definited in main. c文件在另一个文件里面

c - 读取 float 的行并转换为整数

c++ - OpenGL大项目,VAO-s等

c - while (( c = getc(file)) != EOF) 循环不会停止执行

linux - 如何列出以以下开头的所有文件

linux - 在 Linux 内核配置上执行 insmod 的选项有哪些?