JMU
Dynamic Memory Allocation in C++
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Motivation
Diferences between Static and Dynamic Memory Allocation
Pointing to Memory Allocated at Run Time
Pointing to Memory Allocated at Run Time (cont.)
Using Memory Allocated at Run Time
Run Time Allocation of Arrays
Run Time Allocation of Arrays (cont.)
Run Time Allocation of Arrays (cont.)
Run Time Allocation of Arrays (cont.)
Returning Memory to the Heap
Returning Memory to the Heap (cont.)
Returning Memory to the Heap (cont.)
Returning Memory to the Heap (cont.)
Returning Memory to the Heap (cont.)
Returning Memory to the Heap (cont.)
Memory Leaks
Memory Leaks (cont.)
Memory Leaks (cont.)
Memory Leaks (cont.)
Memory Leaks (cont.)
Dynamic Allocation of Objects

A Simple Class to Get Us Started

cppexamples\memory\Weight.h