Lecture notes by: Michael Hahsler
Diagrams for Chapter 1
This chapter is a review of important concepts and their C++ implementation used in this course. Very good short explanations can be found in this C++ YouTube Playlist.
-
Some Questions:
- Where do programs store variables and objects?
- Where does memory come from and how is memory returned?
- What is dynamic memory and why do we need dynamic memory allocation?
- What is the difference between the stack and the heap.
- What happens when you access memory that is not yours?
-
Example: Create a memory diagram for executing the following program:
int inc(int x) return x + 1; int main() { int a = 10; int b = inc(a); return 0; }
-
Video: How do create memory diagrams
-
Call-by-value vs call-by-reference and using
const. -
Reading: References vs. pointers
-
Exercise: Memory allocation
-
What are the differences between memory management in C, C++, Java and Python? (Most programming languages use very similar mechanisms.)
C C++ Java Python Request dynamic memory ? ? ? ? Return dynamic memory ? ? ? ? -
Destructor, copy constructor, assignment operator, and move semantics: The rule of three and the big five for classes.
Most programming languages come with a library of ready-to-use data structures (abstract data types often called collections) and algorithms to supplement
its primitive data types. Java has the Java collections framework including [java.util]. Python has a standard library built into the language.
C++ has the C++ Standard Template Library (STL).
- Reading: The C++ Standard Template Library (STL)
- Examples: Arrays vs STL vectors and C-strings vs STL strings.
- How to compare objects (
operator<and function objects)
All code needs tests! Ways of testing are described in HOWTO Test.
Example: Testing a function to calculate factorials.
All code and documents in this repository are provided under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) License.
