Dynamic Data
- This is chapter 14.2. Read it.
- Up until now, we had to know the size of all of our data containers at compile time.
- Dynamic data allows us to react to data requirements at run time.
- When useing dynamic data we allocate more memory as needed.
- Dynamic storage is created with a call to new
- Dynamic storage is returned with a call to delete
- The lifetime of dynamic storage is between the calls of new and delete.
- Dynamic data is allocated from a structure called the heap
- This is a pool of memory reserved for such data.
- The heap is not inexahustable, therefore all when we are finished with dynamic memory it must be returned to the heap.
- new returns a pointer to a new "chunk" of dynamic memory or nullptr
- delete returns the memory to the ehap.
- new type[int size] returns an array of the given type of the given size.
- delete type[] returns an array to the heap.
- It is an error to delete the same memory twice.