C++ Memory Management

by Patrice Roy

Programming

Book Details

Book Title

C++ Memory Management

Author

Patrice Roy

Publisher

Packt Publishing

Publication Date

2025

ISBN

9781805129806

Number of Pages

402

Language

English

Format

PDF

File Size

4.9MB

Subject

C++ Core Concepts

Table of Contents

  • Foreword
  • Contributors
  • About the author
  • About the reviewers
  • Preface
  • Part 1: Memory in C++
  • Chapter 1: Objects, Pointers, and References
  • Technical requirements
  • Representation of memory in C++
  • Understanding the fundamental properties of objects
  • Arrays
  • Summary
  • Chapter 2: Things to Be Careful With
  • Different kinds of evil
  • Pointers
  • Type punning
  • Summary
  • Chapter 3: Casts and cv-qualifications
  • Technical requirements
  • What is a cast?
  • Safety in the type system – cv-qualifications
  • The C++ casts
  • Summary
  • Part 2: Implicit Memory Management Techniques
  • Chapter 4: Using Destructors
  • Technical requirements
  • On destructors: a short recap
  • Managing resources
  • The RAII idiom
  • Some pitfalls
  • Standard resource management automation tools
  • Summary
  • Chapter 5: Using Standard Smart Pointers
  • Technical requirements
  • The standard smart pointers
  • Type unique_ptr
  • Types shared_ptr and weak_ptr
  • When to use raw pointers
  • Summary
  • Chapter 6: Writing Smart Pointers
  • Technical requirements
  • Ownership semantics
  • Writing your own (naïve) unique_ptr
  • Writing your own (naïve) shared_ptr
  • Writing a policy-based duplicating pointer
  • Some not-so-smart yet useful smart pointers
  • Summary
  • Part 3: Taking Control (of Memory Management Mechanisms)
  • Chapter 7: Overloading Memory Allocation Operators
  • Why would one overload allocation functions?
  • Brief overview of the C language allocation functions
  • Overview of the C++ allocation operators
  • Summary
  • Chapter 8: Writing a Naïve Leak Detector
  • Technical requirements
  • The plan
  • A first implementation (that almost works)
  • Identifying (and fixing) the problems
  • Revisiting our implementation (and lessons learned)
  • Summary
  • Chapter 9: Atypical Allocation Mechanisms
  • Technical requirements
  • Placement new and memory-mapped hardware
  • Simplifying nothrow new usage
  • Out-of-memory situations and new_handler
  • Standard C++ and exotic memory
  • Summary
  • Chapter 10: Arena-Based Memory Management and Other Optimizations
  • Technical requirements
  • Arena-based memory management
  • When parameters change
  • Chunked pools
  • Summary
  • Chapter 11: Deferred Reclamation
  • Technical requirements
  • What do we mean by deferred reclamation?
  • Reclamation (without finalization) at the end of the program
  • Reclamation and finalization at the end of the program
  • Reclamation and finalization at the end of the scope
  • Summary
  • Part 4: Writing Generic Containers (and a Bit More)
  • Chapter 12: Writing Generic Containers with Explicit Memory Management
  • Technical requirements
  • Writing your own vector alternative
  • Writing your own forward_list alternative
  • Better memory management
  • Summary
  • Chapter 13: Writing Generic Containers with Implicit Memory Management
  • Technical requirements
  • Why explicit memory management complicates our implementation
  • Implicit memory management with a smart pointer
  • Consequences of this redesign
  • Generalizing to ForwardList?
  • Summary
  • Chapter 14: Writing Generic Containers with Allocator Support
  • Technical requirements
  • Why allocators?
  • Traditional allocators
  • Polymorphic memory resource allocators
  • Summary
  • Chapter 15: Contemporary Issues
  • Technical requirements
  • Starting object lifetime without constructors
  • Trivial relocation
  • Type-aware allocation and deallocation functions
  • Summary
  • Annexure: Things You Should Know
  • Index
  • Other Books You May Enjoy