mmap示例_mmap教程,带有C和C ++编程语言中的示例

mmap示例

mmap示例

As programmers we generally use malloc() , free() and similar functions in order to allocate memory. They are provided by glibc() library. The actual work is done by mmap() and munmap()which is a Linux systemcall.

作为程序员,我们通常使用malloc()free()和类似函数来分配内存。 它们由glibc()库提供。 实际工作由mmap()munmap() ,这是Linux系统调用。

mmap()有什么功能? (What Does mmap() Function?)

mmap() function or system call will create a mapping in the virtual meory of the current process.The address space consist of multiple pages and each page can be mapped some resource. We can create this mapping for a resources we want to use.

mmap()函数或系统调用将在当前进程的虚拟内存中创建一个映射。地址空间由多个页面组成,每个页面都可以映射一些资源。 我们可以为要使用的资源创建此映射。

图书馆 (Library)

mmap() and munmap() functions are provided by sys/mman.h library. so in order to use we need to include them like below.

mmap()munmap()函数由sys/mman.h库提供。 因此,要使用它,我们需要像下面这样包含它们。

#include <sys/mman.h>

句法 (Syntax)

As mmap() provides flexible memory mapping it has a lot of parameters to use.

由于mmap()提供了灵活的内存映射,因此它具有许多要使用的参数。

void *mmap(void *addr, size_t lengthint " prot ", int " flags ,
           int fd, off_t offset)
  • void *addr is the address we want to start mapping

    void *addr是我们要开始映射的地址

  • size_t lengthint is th

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值