![mmap示例](https://img-blog.csdnimg.cn/img_convert/4a4ead3434c8115648872a2ea6f52819.png)
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 mappingvoid *addr
是我们要开始映射的地址size_t lengthint
is th