Memory Allocation
When you declare an array of size 1000, all 1000 memory locations are
reserved for this array regardless of whether you end up using them or
not.
Static allocation:
all at once
Dynamic allocation:
as needed
Example:
recording names of individuals.
- must accommodate exceptionally long names, say 100 characters.
- static allocation:
- choose max # of names, e.g. 30.
- choose max length of name, e.g. 100, even if most names
require 10 or less.
- allocate 30*100=3000 memory locations.
- dynamic allocation: can just as easily accommodate 30 people
with 100 character names as 300 people with 10 character names.