Constructor Acquires, Destructor Releases Resource Acquisition Is Initialization

Posted rsapaper

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Constructor Acquires, Destructor Releases Resource Acquisition Is Initialization相关的知识,希望对你有一定的参考价值。

w

 

 

https://zh.wikipedia.org/wiki/RAII

RAII要求,资源的有效期与持有资源的对象的生命期严格绑定,即由对象的构造函数完成资源的分配(获取),同时由析构函数完成资源的释放。在这种要求下,只要对象能正确地析构,就不会出现资源泄露问题。

 

https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization

Resource acquisition is initialization (RAII)[1] is a programming idiom[2] used in several object-oriented languages, most prominently C++, where it originated, but also DAdaVala, and Rust. The technique was developed for exception-safe resource management in C++[3] during 1984–89, primarily by Bjarne Stroustrup and Andrew Koenig,[4] and the term itself was coined by Stroustrup.[5] RAII is generally pronounced as an initialism, sometimes pronounced as "R, A, double I".[6]

In RAII, holding a resource is a class invariant, and is tied to object lifetimeresource allocation (or acquisition) is done during object creation (specifically initialization), by the constructor, while resource deallocation (release) is done during object destruction (specifically finalization), by the destructor. Thus the resource is guaranteed to be held between when initialization finishes and finalization starts (holding the resources is a class invariant), and to be held only when the object is alive. Thus if there are no object leaks, there are no resource leaks.

Other names for this idiom include Constructor Acquires, Destructor Releases (CADRe) [7] and one particular style of use is called Scope-based Resource Management (SBRM).[8] This latter term is for the special case of automatic variables. RAII ties resources to object lifetime, which may not coincide with entry and exit of a scope. (Notably variables allocated on the free store have lifetimes unrelated to any given scope.) However, using RAII for automatic variables (SBRM) is the most common use case.

 

以上是关于Constructor Acquires, Destructor Releases Resource Acquisition Is Initialization的主要内容,如果未能解决你的问题,请参考以下文章

智能指针的循环引用与解决

Typescript KeyOf - 数组或对象 - 绝望

通俗易懂,十分钟读懂DES,详解DES加密算法原理,DES攻击手段以及3DES原理。Python DES实现源码

des/3des

aes des 哪个实现简单

[android]DES/3DES/AES加密方式