Jump to content

C++: Difference between revisions

6 bytes added ,  20 October 2023
Line 626: Line 626:
[https://en.cppreference.com/w/cpp/language/raii cppreference raii]<br>
[https://en.cppreference.com/w/cpp/language/raii cppreference raii]<br>
Resource Acquisition Is Initialization - binds the life cycle of a resource to the lifetime of an object.<br>
Resource Acquisition Is Initialization - binds the life cycle of a resource to the lifetime of an object.<br>
For instance, the resource for a vector is an allocated amount of memory. Once the vector is destroyed (destructor called), the resource is released.<br>
For instance, the resource for a vector is an allocated amount of memory. Once the vector is destroyed and the destructor called, the resource is released.<br>
In general, each RAII object should have all of the following:
In general, each RAII object should have all of the following:
* Constructor acquiring resources
* Constructor acquiring resources