Performance & Memory Consideration

Let's weigh the memory and performance constraints when working with std::optional.

We'll cover the following

std::optional Memory Footprint

When you use std::optional, you’ll pay with an increased memory footprint.

The optional class wraps your type, prepares space for it and then adds one boolean parameter. This means it will extend the size of your type according to the alignment rules.

Conceptually your version of the standard library might implement optional as:

Get hands-on with 1200+ tech skills courses.