Reputation: 47
I'm new to C, and I am confused about what allocator can do in C.
Just as the title asked, Can an allocator use the uninitialized data segment to satisfy heap requests if needed?
Upvotes: 0
Views: 1079
Reputation: 30587
The term "memory allocator" does not have any meaning in the standards that define the C language. They do, however, define a set of "Memory Management Functions" that the C Runtime library must provide, so I assume it is these functions you are asking about.
The standards also don't define where or even how the memory is allocated from, just that functions malloc
, calloc
, realloc
and free
must exist and have specified semantics. So, it is up to the implementation to decide where to allocate the memory from.
The term "uninitialized data segment" generally refers to a section of a compiled executable file that specifies that the loader should reserve an amount of memory for the program to use.
In all the implementations I am aware of (or at least those where the term "uninitialized data segment" has meaning), that section is used for uninitialized static variables.
In most implementations, the C Runtime will form the heap by making calls to the OS kernel to obtain block(s) of memory, which it will then allocate to the program.
There is a good description of process memory layout in Linux here.
Upvotes: 2