4 ms·
This is just for resource allocation. The pattern the article talks about is FAR more general -- it's about all reversible processes, even things that have not
by dextorious 15y ago
This is just for resource allocation.
The pattern the article talks about is FAR more general -- it's about all reversible processes, even things that have nothing to do with allocation.
- hythloday 15y agoSentry classes, which are a generalization of RAII, are used idiomatically in C++ for non-allocation tasks, such as whitespace skipping, logging, and profiling.
- JoeAltmaier 15y agoAlso mapping state to scope e.g. mutex objects that set/clear on ctor/dtor
- masklinn 15y ago> This is just for resource allocation. It's the same thing, you can represent the pair (operation, inverse) as a "resource". Python calls it "context management" (and context managers), the means are slightly different, the result's the same. I agree that OP talks about something of a wider scope though, the language features described in these sub-threads are specialized solutions to precise issues, they're not generalized reversal of arbitrary operations.
- Shorel 15y agoWe can add code to destructors to do general stuff, not only deallocation. The same applies for constructors. In C++ this works amazingly well for objects in the stack (not in the heap, as you need call the destructor yourself).