Skip to content
0:00 / 0:00

#allocators#std::allocator#andreialexandrescu

CppCon 2015: Andrei Alexandrescu “std::allocator...”

CppCon

189K subscribers • 101 videos on Hallway • Conference channel

YouTube
  • Recommended by 8 people: 7 on Hacker News and 1 in engineering communities.
  • A classic. People kept recommending it from 2017 to 2025.
  • Presented by Andrei Alexandrescu
  • Linked in the descriptioncppcon/cppcon2015
  • An opinion. It argues one side of a question engineers disagree on.

Advanced. Deep dive for people who know the field.

196K views11 years ago8 recommendations

Systems programmingProgramming languagesC++Memory managementPerformance and optimization

Andrei Alexandrescu critiques C++'s std::allocator and proposes building high-performance allocators from small, composable, templated pieces.

Cppcon.org — std::allocator Is to Allocation what std::vector Is to Vexation -- Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/cppcon/cppcon2015 — std::allocator has an inglorious past, murky present, and cheerless future. STL introduced allocators as a stop gap for the now antiquated segmented memory models of the 1990s. Their design was limited and in many ways wasn't even aiming at helping allocation that much. Because allocators were there, they simply continued being there, up to the point they became impossible to either uproot or make work, in spite of valiant effort spent by the community. But this talk aims at spending less time on poking criticism at std::allocator and more on actually defining allocator APIs that work. Scalable, high-performance memory allocation is a topic of increasing importance in today's demanding applications. For such, std::allocator simply doesn't work. This talk discusses the full design of a memory allocator created from first principles. It is generic, componentized, and composable for supporting application-specific allocation patterns. — Andrei Alexandrescu is a researcher, software engineer, and author. He wrote three best-selling books on programming (Modern C++ Design, C++ Coding Standards, and The D Programming Language) and numerous articles and papers on wide-ranging topics from programming to language design to Machine Learning to Natural Language Processing. Andrei holds a PhD in Computer Science from the University of Washington and a BSc in Electrical Engineering from University "Politehnica" Bucharest. He works as a Research Scientist for Facebook.Website: erdani.comTwitter handle: @incomputable — Videos Filmed & Edited by Bash Films: BashFilms.com Work at Hudson River Trading (HRT): tinyurl.com/safxfctf

Why it's here

8 people recommend this

What people say. Engineers recommend this talk as a brilliant, entertaining, and eye-opening explanation of modular allocator design in C++.

Moments people linked to

nlyon Hacker News • Recommends

On “The Horror in the Standard Library”

Actually it is C's malloc and free that is "broken". malloc() takes a size parameter, but free() doesn't. This imbalance means it can never be maximally efficient. Whatever GNU stdlibc++ is doing is probably, on balance, a net win for most programs. It's not exactly roses in C++ either of course. You can do better than the standard library facilities. Andrei Alexandrescu gave a great, entertaining, and technically elegant talk on memory allocation in C and C++ at Cppcon 2015 that is well worth watching link to this video

p0nceon Hacker News • Recommends

On “Using D to Create the World’s Fastest File System”

> I would have liked to hear more about what exactly made D so great This WIP article explains very well the USP of D: link (section 3) This article highlight the value of "design-by-introspection" applied to a particular problem space: link This talk present a concrete example of such: link to this video (mind bending stuff) You might not understand what is new about it, but soon your competitors will understand it.

favoritedon Hacker News • Recommends

On “Benchmarking C++ Allocators”

A bit unrelated, but if anyone is interested, I recently watched Andrei Alexandrescu's 2015 talk about a composable allocator design in C++ and it was really interesting. And Andrei's presentation style was fantastic, per usual. Note that this talk is about a std::allocator-like type, potentially on top of one of malloc/jemalloc/etc. link to this video

favoritedon Hacker News • Recommends

On “Custom Allocators Demystified”

Andrei Alexandrescu's 2015 talk about C++'s allocators is great. He's a very entertaining presenter, and he makes case for extremely composable templated allocators (and why std::allocator isn't that). link to this video

jiggawattson Hacker News • Recommends

On “Writing a Memory Allocator (2019)”

Every time I hear someone talking about writing a memory allocator, it always reminds me of the brilliant CppCon 2015 talk by Andrei Alexandrescu about how he wrote an modular allocator library that can be built up in pieces to make whatever you like. link to this video

jiggawattson Hacker News • Recommends

On “Ask HN: What's the best lecture series you've ever seen?”

Not exactly a lecture series, but Andrei Alexandrescu has had some fantastic keynote presentations at CppCon. I don't even program in C++ any more, but I've watched these more than once, they're entertaining, approachable, and inspiring: Speed Is Found In The Minds of People link std::allocator Is to Allocation what std::vector Is to Vexation link to this video An actual lecture series I've enjoyed watching is "The WE-Heraeus International Winter School on Gravity and Light", which covers General Relativity using modern mathematical approaches: link Again, I haven't done physics in 20 years, but I've found it surprisingly easy to follow because it is so clearly presented.

jiggawattson Hacker News • Recommends

On “Comptime as Configuration”

…his is sort-of my point! For example, what's the fundamental difference between allocating memory in some heap1 structure at runtime and a compiler allocating members in a struct/record/class for optimal packing? IMHO, not much. E.g.: Watch this talk by Andrei Alexandrescu titled "std::allocator Is to Allocation what std::vector Is to Vexation": link to this video It really opened my eyes to how one could very elegantly make a very complex and high-performance heap allocator from trivial parts composed at compile-time. There's no reason that a nearly identical abstraction couldn't also be used to efficiently "bin pack" variables into a struct. E.g.: accounting for alignment, collecting like-sized ite…

u/cxzukin r/ProgrammingLanguages • Recommends

DRAFT: Allocators and Reference Types Hi all My main PLDI activity is on an OOP language, but I had a few days off and got distracted with Systems Programming languages, and specifically, Allocators (Strategies, Composability and Framework) and Reference Types. Heavily influenced by CppCon 2015: Andrei Alexandrescu “std::allocator...” (Which is, unfortunately slide-ware). This is a spiritual progression on this talk. I've done a lot of research, and started writing up my thoughts and opinions on this topic to highlight the importance of acknowledging allocators when designing a programming language. I have also provided a small illustrative library on the design too. I have unfortunat…

badsectoraculaon Hacker News • Recommends

On “Show HN: Crown – A flexible game engine written from scratch in C++”

…worked at, for example, had its own containers and memory allocator and allowed you to define the allocation category and pool per allocator and per object class (so, e.g., dynamic strings would be isolated to their own pool to avoid fragmenting the heap). Related, Andrei Alexandrescu had a great talk about allocators in C++ a couple of years ago: link to this video Also related to the Orthodox C++, the same engine also ousted exceptions and RTTI. I'm not sure about the reason for exceptions, but C++'s RTTI was simply inadequate and instead it was replaced with a custom one made using macros (similarly to wxWidgets and MFC) that allowed automatic object serialization and reflection which was used for a…

Quekid5on Hacker News • Recommends

On “Mimalloc – A compact general-purpose allocator”

Andrei Alexandrescu had a great talk0 on allocators and this convinced me that if you really care about allocator performance1 what you need is a tunable and composable system. The whole idea of how and when (runtime/compile-time) to choose the appropriate allocator is also interesting. 0 link to this video 1 I suppose there's a digression to be had here about allocation being trivial and RAII-style deallocation not really being deterministic, but...

jiggawattson Hacker News • Recommends

On “How to write untestable code (2008)”

…oolean logic, which I guarantee you contain at least a dozen bugs, no matter how much you think you've tested it. Code coverage is like those skin creams that say "Scientifically tested!" on the label. Yeah, well, tested doesn't mean that it worked. It just means that there was a test. Watch this video of Andrei Alexandrescu's talk in CppCon 2015: link to this video I've done things like this in my career, and it's always worked out brilliantly . Bugs just evaporate when you let the compiler "combine" things for you, instead of just plopping everything into a bowl and mashing it together with your hands like some sort of animal. Especially in today's C++ or Rust, you can "have your cake and eat it too"…

einpoklumon Hacker News • Recommends

On “C++ Should Be C++”

Allocators have an inherently broken design, tying them to types. See this CppCon talk by the (engaging and funny) Andrei Alexandrescu: link to this video std::allocator is to allocation what std::vector is to vexation (or: designing allocators that don't not-work)

u/InnPatronin r/ProgrammingLanguages • Mentions

On “How are allocators made?”

1. The goal is to make allocators composable: meaning that when you hand a chunk of memory to an allocator, it manages that chunk independently of any other allocator. This gives you the nice property that you can nest allocators in each other (by allocating a sub-chunk and giving it to a new allocator). Conceptually, you start of with a `Base` allocator which interfaces directly with the underlying memory API and just make new allocators from there. 2. The free-list allocator can be implemented as an intrusive, doubly-linked list. ``` FreeList = Node | null Node = { prev: Node | null, size: usize, isFreeFlag: bool } ``` Each `Node` represents a sub-chunk of the Free-List's allocated me…
20View on Reddit

u/cxzukin r/ProgrammingLanguages • Mentions

On “Memory Management Examples?”

Hi Salt, Oh man, you PLDI'ers are asking all the tough questions this week. I've more questions than answers but can tell you my thoughts at present - In the last ~6 months, I've been viewing memory management in terms of Graph theory (Nodes and Edges). Edges are pointers, and Nodes are "blob" in memory - malloc'd block, struct/class instance, stackframe/activation record. etc Graph theory gives us information and understanding on connections of the types (in simple to complex order) e.g: 1. Single parent, Single Child List 2. Single parent, Multiple children Tree 3. Multiple Parents (Acyclic) DAG 4. Full Graph (Cycles) Graph In the square brackets is the…

u/skeetoin r/C_Programming • Mentions

On “I implemented a buddy allocator!”

Interesting! Thanks for letting me know. One should avoid general purpose allocation, even stepping back and changing the problem constraints if possible (i.e. not designing an API that requires general purpose allocation underneath), but some situations intrinsically call for it, in which case your buddy allocator would be useful. Buddy and arena allocation aren't necessarily mutually exclusive, Composing them might allow a program to be expressed more clearly or simply. For example, imagine running a little programming language (lisp, etc.) that may allocate arbitrarily, which an arena wouldn't handle well: result run_program(str source, arena scratch) { program p = co…

u/N-R-Kin r/C_Programming • Mentions

On “Best Third Party Garbage Collection/RAII Library for C”

> what if you are allocating containers that dynamically grow "Dynamically grow" and "grow in place" are different. For the first one, arenas impose no problems. For example, you could use a hash-trie (also) for building an "unordered map", it requires no resizing and was specifically designed to work with arenas. For the latter case of growing *in place* (e.g dynamic array) - the question is, is it temporary or long lived allocation? If it's just a temporary thing that will be discarded soon, then you can allocate a new and ignore the old allocation (example (https://nullprogram.com/blog/2023/10/05/), near the end it also contains a trick to extend in place if no other allocation interf…