7/24/2026 at 8:27:22 AM
I have a little class called EImpl that is kind of like std::indirect except that it embeds the impl instead of pointing to it. It takes three template parameters: an embedded struct, a size and an alignment. It static_asserts that the embedded struct fits in the size and alignment, and it embeds it with approximately zero overhead. It’s about as easy to use as any other pImpl technique.by amluto
7/24/2026 at 11:16:40 AM
But if the pimpl size grows too big, you're forced to break ABI?And before it grows too big, it wastes memory. For your use cases it may not matter, and the saved pointer indirection may be more important, but maybe the person who has a million item vector of objects doesn't appreciate a 300% "just in case" memory overhead. The overhead may also hurt cache hits.
If you're doing this to save the pointer indirection, you should benchmark it for every use case, since negative cache effects may dwarf that gain.
Then again, extra padding can also help performance, for some workloads (especially multi threaded read/write against a vector of objects).
So without further context, there's no way to say if your way hurts or helps. It's certainly not a general solution.
by knorker
7/24/2026 at 1:05:38 PM
I use it in a monorepo to break compile-time dependencies. If I need to adjust the size, I spend a minute or two rebuilding.by amluto
7/24/2026 at 1:55:57 PM
Yup, agree that in some cases this fixes it. Indeed, in another comment[1] on this comment branch I said "Not everyone works at Google and builds all binaries from scratch from a monorepo every time".So you're only trying to solve compile time issues (incremental and not)? Maybe the right long term solution is C++ modules, instead? And maybe "just" a matter of having your build environment support modules?
by knorker
7/25/2026 at 11:33:00 AM
> And before it grows too big, it wastes memoryhow it wastes the memory? It's just a bytes array of the same size as struct. I would be more imposed on how idiomatic pimpl with heap allocation influences memory usage and cache hits
by feelamee
7/24/2026 at 11:33:46 AM
"Breaking ABI" isn't an issue unless you can't compile your code anymore. It's pathetic that C++ has been so hamstrung over ABI that we're willing to stop improving.by StilesCrisis
7/24/2026 at 12:51:43 PM
Not everyone works at Google and builds all binaries from scratch from a monorepo every time. And even then, maybe even Google doesn't rebuild libstdc++ as part of this.GNURadio consistently uses pimpl for blocks, as I understand it mainly for ABI.
> willing to stop improving.
I think that dismissing it like that shows a naive understanding of execution environments, binary interface design, and in general systems software engineering.
by knorker
7/25/2026 at 2:38:09 PM
If you want a fixed build environment, pick a toolchain and stick with it.If you want the latest and greatest, a willingness to rebuild your code seems like a reasonable prerequisite to me.
If you need a binary blob that can withstand toolchain versioning, use a dynamically linked library.
by StilesCrisis
7/24/2026 at 12:55:19 PM
Unfortunately I have some customers of my library that won't recompile. Hard to blame them because it is safety critical and needs recertification. In just glad the certification process is willing to not recertify my code when I change itby bluGill
7/25/2026 at 7:59:42 AM
Because outside Linux and BSD distros, the large majority of C and C++ developers care about binary libraries, and companies do make a business out of it.So regardless of what WG14 and WG21 do, compiler vendors will ignore them, if it means angry customers.
In design by committee languages, new standards are only relevant to the extent implementers actually care about them.
by pjmlp
7/25/2026 at 2:08:48 AM
Related: polymorphic_value https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p02...by dataflow
7/25/2026 at 9:25:58 AM
Do you have the code shared somewhere, via a blog post or code snippet somewhere?by daemin