malloc returns memory or virtual address space

前端 未结 15 2034
攒了一身酷
攒了一身酷 2021-01-31 06:36

Does malloc allocate a block of memory on the heap or should it be called Virtual Address Space?

Am I being picky calling it Virtual Address Space or this just the legac

15条回答
  •  甜味超标
    2021-01-31 07:12

    malloc is a library call. On linux, it in turn calls sbrk system call. sbrk will increase the size of heap but does not actually allocate physical memory. When the process tries to access this address, a page fault is raised and then at that time kernel allocates actual physical page and maps to the virtual address.

    TL;DR: malloc returns a virtual address and does NOT allocate physical memory.

    Check this out.

提交回复
热议问题