Processes
The memory chunk that a process controls contains several sections:
- The text section, in which the binary code of the program (the process's instructions) is stored. This section is fixed in size (depending on how long the binary code is.)
- The data section, in which global and static variables are stored. It has a fixed size, too. (Why so?)
- The stack section, in which local variables, such as those defined inside functions, are stored, and
- The heap section, in which variables that were dynamically allocated are stored. E.g.: when you use the new operator in java, your variable (or object) is stored on the heap.
Note that the stack and the heap start at opposite ends of the process's free space and grow towards each other since the size of the stack or heap could change over the process's execution. If they should ever meet, then either a stack overflow error will occur, or else a call to new or malloc (the function the language C uses to allocate memory) will fail due to insufficient memory available.