在 mmap() 联机帮助页中:
它的原型是:
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
和描述:
The mmap() function asks to map 'length' bytes starting at offset 'offset'
from the file (or other object) specified by the file descriptor fd into
memory, preferably at address 'start'.
具体来说,对于最后一个论点:
'offset' should be a multiple of the page size as returned by getpagesize(2).
根据我的实践,offset
必须是页面大小的倍数,例如,我的 Linux 上的 4096,否则 mmap() 会返回Invalid argument
,offset
是文件偏移量,为什么它必须是虚拟内存系统页面大小的倍数?
谢谢,