Chapter 3
Classes
Section 5
Resource Acquisition is Initialization
Resource Acquisition Is Initialization (RAII), is a programming idiom that is used to manage the life cycle of a resource automatically by binding it to the lifetime of an object. This can be achieved through smart use of the constructor and destructor of an object. The former acquires the resource, while the latter realizes it. The constructor is allowed through, for example, when a resource cannot be acquired, while the destructor never throws exceptions. It is a good practice to operate on a resource of a RAII class when its usage involves open()/close(), lock()/unlock(), start()/stop(), or init()/destroy() function calls.