Dynamic Memory
Allocate memory at runtime with new and delete. Understand stack vs heap and avoid memory leaks.
Lessons
1. Intro
Memory control
2. Stack vs Heap
Memory layout
3. Stack Memory
Local variables
4. Heap Memory
Long-lived data
5. The new Operator
Heap allocation
6. Quiz: Memory Basics
Memory allocation
7. The delete Operator
Manual cleanup
8. new and delete for Arrays
Heap array allocation
9. Quiz: Memory cleanup
Memory cleanup
10. Quiz: new and delete
Knowledge check
11. Memory Leaks
Forgetting delete
12. Dangling Pointers
Deleted memory access
13. Double Delete
Repeated free
14. nullptr After delete
Defensive programming
15. When to Use Dynamic Memory
Allocation decisions
16. Quiz: Memory cleanup
Memory cleanup
17. Dynamic Arrays
Variable-sized allocation
18. Resizing Dynamic Arrays Manually
Grow and shrink
19. Quiz: Memory Leaks
Knowledge check
20. Problems with Raw Pointers
Manual management risks
21. Introduction to Smart Pointers
Automatic cleanup
22. What is unique_ptr?
Single owner
23. Creating unique_ptr
Factory function
24. unique_ptr Automatic Cleanup
Scope-based delete
25. Quiz: Knowledge check
Knowledge check
26. Moving unique_ptr
Ownership transfer
27. Quiz: unique_ptr
Knowledge check
28. What is shared_ptr?
Multiple owners
29. Creating shared_ptr
Factory function
30. Reference Counting
Ownership tracking
31. When shared_ptr Deletes
Last owner cleanup
32. Quiz: Variable alias
Variable alias
33. weak_ptr Basics
Non-owning reference
34. Quiz: shared_ptr
Knowledge check
35. Choosing the Right Smart Pointer
Ownership patterns
36. Smart Pointers vs Raw Pointers
Modern C++ practice
37. Practice Problems
Apply what you learned
38. Quiz: Smart Pointer Choice
Knowledge check
39. Problem - Flexible Array
Heap memory basics
40. Flexible Array - The Idea
Memory location matters
41. Flexible Array - Algorithm
Implementation approach
42. Flexible Array - Implementation
Pseudocode solution
43. Lessons from Flexible Array
summary
44. Problem - Node Creation
Heap-based data structures
45. Node Creation - The Idea
Building chains
46. Node Creation - Algorithm
Implementation approach
47. Quiz: Knowledge check
Knowledge check
48. Node Creation - Implementation
Pseudocode solution
49. Lessons from Node Creation
summary
50. Section Recap
What we learned