1

This question is going to be a bit vague since I do not exactly know what I am talking about. Bad start, I know, but let me explain.

So, I am currently writing a small virtual machine just for fun, and now I'm at the stage where I'm trying to create some form of heap. While researching I stumbled upon the function mmap(), which I've read can be used for mapping a file in the virtual address space.

But, I've recently seen it being used with the flag MAP_ANONYMOUS by multiple virtual machines to allocate memory. How is mmap used in this case?

Can it be used just like malloc if I do something like this: mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); (I stole that from cpython on github).

Zyphicx
  • 299
  • 2
  • 13

0 Answers0