Memory Management
- This is part of chapter 7.
- We will discuss raw pointers now
- We will discuss pointers and arrays later.
- We will discuss "smart" pointers much later on.
- You should read
- 211 to 215
- 227 to 234
- Probably the other parts too, but that is for later.
- For now ignore
- The dire warnings about raw pointers.
- The discussion of smart pointers.
- But do read, and pay attention to the gray boxes.
- As a C/C++ programmer, you are expected to be able to deal with dynamic memory.
- Read the chapter intro on 211. I love it.
- "A solid understanding of how dynamic memory really works in C++ is essential to becoming a professional C++ programmer"
- What is dynamic memory? What is static memory?
- Why do we need dynamic memory?
- What is the runtime stack? What is the heap?
- How do we allocate memory from the heap?
- How do we return memory to the heap?
- An abstract data type is a data type where we know the domain and operations but do not know how it will be implemented.
- What is a stack? (think in terms of ADT)
- Domain :
- A collection of homogeneous data, 0 or more elements
- Ordered by time inserted
- First In Last Out or Last In First Out
- Only access to the item on top.
- Operations?
- Push: add an item to the stack
- Pop: remove the top item from the stack
- Top: get a copy of the top item on the stack.
- Size: get how many values are stored on the stack.
- IsEmpty: return true if the stack is empty, false otherwise.
- How would you draw this in a UML diagram?
- What are the performance expectations for a stack?
- How could you implement a stack?