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
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?
malloc
allocates a block on the heap. For each memory page that the allocated block spans, there may or may not be physical memory committed to it at the outset. The entire block is usable though, since the OS will take care of handling page faults and managing physical/virtual memory that's needed to support the allocation.
The answer depends on the underlying OS, libc implementation, and hardware architecture. With most modern OS'es (like Linux or Windows) running on the x86 architecture you will get a pointer within the linear address space, but generally this is implementation dependent. I doubt that when, for example, programming some small device (like a microcontroller) in C, malloc() would return a pointer to virtual memory, because there is no virtual memory as such.