Skip to content

kevinbcarpenter/b2b-custom-allocators

Repository files navigation

Back 2 Basics: Custom Allocators

Presented

  • Meeting C++ 2024 (alternative title)
  • CppCon 2025

Alternative titles

  • Mastering Memory Management in C++: How to use Custom Allocators

Submission Details

Tags: standard library, allocators, containers, data structures, cpp17, cpp20, cpp23 
Session Type: Back to Basic
Level: Beginner, Intermediate
Audience: application developers, students
Session Material: slides, example code 

Abstract

Effective memory management is crucial for building efficient and reliable C++ applications. Custom memory allocators provide a powerful tool for optimizing memory usage, reducing fragmentation, and improving performance. This talk will explore the intricacies of memory allocation in C++, from the basics of dynamic memory management to the implementation of custom allocators. Attendees will gain insights into the standard allocator model, techniques for designing custom allocators, and practical examples of their use in real-world applications.

Join us to unlock the full potential of memory management in your C++ projects.

Outline

  • Introduction (15 minutes)
    • The importance of memory management in C++
    • Items in Memory (object representation)
    • Basics of alignment and padding
    • Overview of dynamic memory allocation
    • Introduction to custom allocators
  • Standard Allocator Model (10 minutes)
    • Overview of the C++ Standard Library allocator model
    • Understanding the std::allocator class template
    • Basic usage and customization of std::allocator
  • Designing Custom Allocators (15 minutes)
    • Key components of a custom allocator
    • Implementing allocator traits
    • Writing a simple custom allocator from scratch
  • Memory Allocation Strategies (15 minutes)
    • Pool allocators and their advantages
      • show a memory pool where we hold space for X transactions for processing
      • come in from say http
      • held in memory till processed
      • then deleted till next one comes in to http.
    • Stack-based allocation and arena allocators
    • Strategies for minimizing fragmentation and overhead
  • Advanced Allocator Techniques (15 minutes) and Performance Considerations (10 minutes)
    • Stateful allocators and their use cases
    • Allocator-aware containers and algorithms
    • Measuring allocator performance
    • Examples of allocator optimization
    • Trade-offs
  • Conclusion (5 minutes)

Additional Notes

  • Incorporate interactive coding sessions to demonstrate key concepts.
  • Use visual aids to explain complex memory management techniques.
  • Provide handouts or online resources for further study and practice.

https://johnnysswlab.com/the-price-of-dynamic-memory-allocation/

AI Learnings https://stackoverflow.blog/2024/09/23/where-developers-feel-ai-coding-tools-are-working-and-where-they-re-missing-the-mark

Padding and Alignment https://www.youtube.com/watch?v=E0QhZ6tNoRg

License

Back 2 Basics: Custom Allocators  © 2024 by Kevin B. Carpenter is licensed under Creative Commons Attribution 4.0 International. To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0/

About

Custom Allocators Talk for CppCon 2025

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published