作者RiverJackson (JACK)
看板LinuxDev
標題[問題] mmap memory issue
時間Fri Dec 18 17:52:39 2009
請問一下
我去開hello這個檔案
但是free一下 並沒有減少 4M空間(4000000)
還有為什麼p 要宣告成int呢
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
int main(void)
{
int *p;
int fd = open("hello", O_RDWR);
if (fd < 0) {
perror("open hello");
exit(1);
}
p = mmap(NULL, 4000000, PROT_WRITE, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) {
perror("mmap");
exit(1);
}
close(fd);
p[0] = 0x30313233;
munmap(p, 6);
return 0;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.134.126