COMP1927 - Memory Model

Compile Time

  • Code:
    • Machine code
    • Fixed size at compile time
    • Read only
  • Global Data:
    • Global Variables
    • Fixed size at compile time
    • Read/Write area
  • Heap
    • Initialised at compile time
  • Stack
    • Initialised at compile time

Run Time

  • Code:
    • Run and not changed
  • Global Data:
    • Could be changed
  • Heap:
    • Dynamic data structures – e.g. created with malloc() and deleted with free()
  • Stack:
    • Function calls
    • 1 Stack frame per function call
    • Automatically created and deleted with function start/end

The heap and stack start at opposite ends (top/bottom) of the available memory, and build in opposite directions. They can swap depending on the architecture.

If they collide you have run out of memory.