There are other ways of writing code—which other languages can incentivize by being designed differently—where it is not a niche optimization, but rather the default.
There are other ways of writing code—which other languages can incentivize by being designed differently—where it is not a niche optimization, but rather the default.
Heap allocations can be done about 10 million times a second on one core, once you get them out of your loops they should make almost no impact, so grouping a few together when they are only being done once is rare and probably indicative of painting yourself into a corner where something inside a call stack inside hot loop still has to heap allocate.
The other reason is that most heap allocation is for lots of memory that will hold the same type. Manually grouping a bunch of allocations implies that you have multiple different types of arrays all buried inside a hot loop to the extent that you are trying to shave off whatever you can but can't lift those allocations out of the loop.
It basically implies that the optimization has to come without too many changes, because if you could do whatever you want they wouldn't be in the loop in the first place. For these reasons it is a half measure in a niche scenario.
There are other ways of writing code—which other languages can incentivize by being designed differently—where it is not a niche optimization, but rather the default.
This is completely abstract, can you show me exactly what you mean and why it can't be done easily in C++ or with RAII ? It sounds like rationalizing a situation you don't want to be in in the first place.