3 ms·
Resource Allocation Is Initialization is one of the central themes in C++. > one still has the option of passing the preallocated objects via constructor param
by jstimpfle 8y ago
Resource Allocation Is Initialization is one of the central themes in C++.
> one still has the option of passing the preallocated objects via constructor parameters, or customize allocation via an allocator
I'd rather just allocate_the_thing(); initialize_the_thing(); do_things_with_the_thing(); free_the_thing(); which makes it very easy to pull these farther away from each other, or to perform bulk operations over many "objects". In other words, I just want to do what needs to be done, when it needs to be done, and not have to build and use awkward semantically heavy trap doors (rvalue references?) to not do the systematic things that weren't a good idea in the first place.
- gpderetta 8y agoThe A in RAII is for acquisition and it is about ownership, not allocation. You can do exactly those things in C++ (operator new or allocators, T::T(), T::~T(), operator delete). The language just gives the tools to distinguish a bunch of uninitialized memory from an actual T which holds its invariant (if any).
- jstimpfle 8y agoOk acquisition it is. I don't even understand the difference. Wikipedia doesn't seem to make a distinction either. Uninitialized memory is all I ever want. And I want to simply write to that memory when the time has come, not hide those writes in a T::T() somewhere in an isolated file with lots of braces and spaces and colons and only few things that actually happen. It's really hard to map out the codepath of a project with lots of constructors and inherited constructors 15 levels down the call stack. Same applies for running it in a debugger.