malloc returns memory or virtual address space

前端 未结 15 1842
攒了一身酷
攒了一身酷 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:16

    • malloc() does allocate a block of memory on the HEAP.

    • Should it be called virtual address space? Hold that thought for a second. VAS (virtual address space) is a memory mapping mechanism that comprises the entire memory space of an application. In other words, VAS is not restricted to the memory area of the HEAP. The HEAP is actually just another part of it.

    Each time a new application is run, the OS creates a new process and allocates a new VAS for the application. Memory allocated through malloc() is reserved on the HEAP, which is a special memory region within the VAS, as you know, and memory allocated through standard means ends up in the stack, which is another region of memory located inside the VAS of the application.

提交回复
热议问题