malloc returns memory or virtual address space

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

    malloc() specifically allocates from the heap.

    Whether the heap memory is in a virtual address space or not depends entirely on the operating system and hardware architecture. On a system with an MMU and an operating system that utilises it, all memory (heap, code space, stacks, static memory and memory mapped I/O etc.), exists in a virtual space, even if the physical to virtual mapping is one-to-one.

    To have a virtual address space requires an MMU to map physical to virtual addresses, not all targets have an MMU, so heap memory and virtual memory are not synonymous or interchangeable concepts in any way; they are entirely independent concepts.

    With respect to "Virtual Address Space" being a "the legacy of DOS", you could not be further from the truth, 16 bit x86 architecture does not support an MMU or virtual memory at all. I wonder how you got that idea?

提交回复
热议问题