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
You could have answered this question yourself if you had bothered to RTFM :-)
In particular, typing man malloc
on a Linux machine and searching (one-at-a-time) for "heap" and "virtual" will let you see unambiguously that malloc()
is defined in terms of heap memory, rather than virtual memory.
The Wikipedia article for malloc()
agrees with the Linux man page. It states (emphasis is mine):
In C, the library function
malloc
is used to allocate a block of memory on the heap. [...] Some platforms provide library calls which allow run-time dynamic allocation from the C stack rather than the heap (e.g. Unixalloca()
, Microsoft Windows CRTL'smalloca()
). This memory is automatically freed when the calling function ends. The need for this is lessened by changes in the C99 standard, which added support for variable-length arrays of block scope having sizes determined at runtime.
If you are confused about the meaning of terminology, then the Wikipedia articles on heap memory and virtual memory may help you.