(C++) memory

January 11, 2018 · View on GitHub

 

 

 

 

 

(C++) memory

 

A computer's memory is the amount of fast non-permanent data (RAM) that is, among others, used for calculations.

 

C++ uses the following major distinct memory areas [1]:

 

  • Const data: const data known at compile time
  • Stack: automatic variables that live in their scope
  • Free store: dynamic memory area allocated/freed by new/delete. Prefer using the free store [2]
  • Heap: dynamic memory area allocated/freed by malloc/free. Avoid using the heap [3]
  • Global/static: global/static variables that are initialized at program startup

 

 

 

 

 

References

 

  1. Herb Sutter. Exceptional C++. ISBN: 0-201-61562-2. Item 35: Memory Management - Part 1: Table 1
  2. Herb Sutter. Exceptional C++. ISBN: 0-201-61562-2. Item 35: 'Prefer using the free store (new/delete)'
  3. Herb Sutter. Exceptional C++. ISBN: 0-201-61562-2. Item 35: 'Avoid using the heap (malloc/free)'