Mastering memory efficiency with std::span

A useful C++20 tool for providing a non-owning view of contiguous memory

CMP
6 min readAug 21, 2023

--

Before diving into the usage of std::span, it is important to understand the concept of ownership of resources. When a container such as a std::vector is created, the container has ownership of the memory used to store data inside of it, meaning that it is the responsibility of the container to manage the lifecycle of this memory. Let’s look at a few common scenarios where a std::vector is used and determine if the ownership is affected:

--

--

CMP

Software engineer specializing in operating systems, navigating the intracicies of the C++ language and systems programming.