Module 5 - C++: Thinking about memoryModule Overview
./../../private/data/5/header.jpg
./../../private/data/5/header2.jpg
./../../private/data/5/header3.jpg
×
1.) C++ is not the C Language -- Course Introduction
2.) C++ Batteries Included - STL and GDB Debugging with the STL
3.) Functions 1: Making our code more modular | GDB and Functions
4.) Input and Output
5.) C++: Thinking about memory
6.) Memory Allocation and Layout
7.) Arrays, Splines, and SFML Library Introduction
☰ Select another Module

Audio/Video Recording

...Commented Code Samples (if any)

For now I am linking code samples here: Github Code Repository for the course
...

Additional Resources


Slides


(Graded) In-Class Activity link

  • In-Class Activity Link
    • This is graded, and only your first response is graded
    • This is an evaluation of what was learned in lecture.
    • Due one week from when the lecture takes place

Module Content

Module Overview

In this module we discuss memory, arrays, and pointers!


Module Outline

  • Lecture outline
    • Revisiting arrays and raw arrays
    • arrays
    • Raw Pointers
    • Pointer Arithmetic
    • Segmentation fault in GDB

Commentary

Prev
(Optional Notes)

Computer Memory

As a programmer, we will often have to think about the memory on our machines. The reason we have to reason about memory is due to space constraints, but more often for performance for desktop applications. Noaw as a consumer (let's say if you're building your own computer), you probably thin about memory at the hardware level thinking in terms of the computers hard drive that you have to purchase or perhaps making a decision on how much RAM (usually meaning DRAM -- those little green sticks) you want to purchase. These are all very important components for us to know about, though for now I want to focus on memory from a programmers perspective.

Memory visualization

One luxury we have from the programmers persective, is that we can start by thinking about our working memory as a long linear area of addresses where we can store data.

TODO: Add figure of a long tape of memory

A mechanism known as virtual memory allows most programmers to simply think of memory as this long tape of addresses the size of our working memory.

Note: Programmers on embedded devices, gaming consoles, or other specific domains may not be able to make the same assumptions about having virtual memory. Virtual memory is an abstraction provided by an operating system and often assisted by hardware.

Retrieving Addresses - The '&' Address of operator

What happens when we call a function?

Pass by Value Semantics

Pass by value semantics

Pass by Reference Semantics

Pointers

A pointer is a variable type that stores an address.

Q & A

When to use pass by pointer versus pass by reference (see slides)

Please do not redistribute or host any materials without e-mailing me first. I generally am happy to share the latest .pdf or slide presentation with those who ask. Thank you for your time!