C++ Is Not Memory-Safe
If you still write C++ like it’s 2000
C++ has its issues in terms of safety, and memory can be a part of it. Two types of memory issues exist: spatial and temporal. Spatial issues refer to accessing memory outside of the bounds, while temporal issues refer to accessing memory in an uncertain or freed state. Modern C++ attempts to avoid many of the pitfalls by avoiding the usage of naked pointers and through the use of std::span
or concepts. There’s still work to do, though; we will show in this chapter that the current C++ mechanisms are still incomplete and look at safety profiles as a possible future improvement.
In this chapter, we’re going to cover the following main topics:
- Memory safety is important
- The memory safety problems of older C++
- Modern C++ to the rescue
- The limits of modern C++
- There’s still more to do