mmap with /dev/zero

后端 未结 2 1309
一个人的身影
一个人的身影 2020-12-06 01:31

Say I allocate a big memory (40MB) with mmap using /dev/zero as follows.

fd = open(\"/dev/zero\", O_RDWR); 
a = mmap (0, 4096e4, PROT_READ | PROT_WRITE, MAP_         


        
2条回答
  •  Happy的楠姐
    2020-12-06 01:52

    Yes, even more the pages are only brought into existence if you touch them for the first time.

    BTW, there is the flag MAP_ANONYMOUS that you can use in this situation, no need to open a file descriptor on /dev/null.

提交回复
热议问题