Hi, everyone. When I refer the document of thread library, a word "RALL-style" appear in the introduction of the class lock_guard: This provides simple RAII-style locking of a Lockable object, to facilitate exception-safe locking and unlocking. I didn't got the main point of this word "RALL-style", could anyone tell me the meaning ? Thanks. Best wishes.
It's not RALL, it's RAII, i.e. Resource Acquisition is Initialization. Wikipedia has a reasonable treatise on it: http://en.wikipedia.org/wiki/RAII Benjamin
Hi, Benjamin. Thanks for your help first of all. I am sorry, I have made a mistake that error spelling "RAII". With my best wishes. -----邮件原件----- 发件人: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] 代表 Benjamin Lau 发送时间: 2009年5月1日 13:20 收件人: boost-users@lists.boost.org 主题: Re: [Boost-users] What does "RALL-style" means ? It's not RALL, it's RAII, i.e. Resource Acquisition is Initialization. Wikipedia has a reasonable treatise on it: http://en.wikipedia.org/wiki/RAII Benjamin _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
AMDG ZouLei wrote:
When I refer the document of thread library, a word "RALL-style" appear in the introduction of the class lock_guard: This provides simple RAII-style locking of a Lockable object, to facilitate exception-safe locking and unlocking.
I didn't got the main point of this word "RALL-style", could anyone tell me the meaning ? Thanks.
It's RAII, not RALL, and it stands for Resource Acquisition Is Initialization. I basically means that every resource, such as a lock, is owned by an object whose destructor releases it. In Christ, Steven Watanabe
A lot of things can be partitioned into do-actions and undo-actions.
E.g. resource allocation and deallocation.
According to this philosophy you should perform do-actions in a constructor and the matching un-do action in a destructor.
Throw an object containing rich error information in case of the do-action fails.
The win32 library can be nicely wrapped into such classes.
When you're going this way you can chain such objects into base class and member class relationships.
You only have to write code for the successful case.
The compiler will generate code, to deal with the case any of the base or member object fails to initialize.
Try to allocate only a single resource in a single constructor.
Otherwise you will have to deal with failure by yourself instead of leaving this up to the compiler.
Another good philosophy (which may be derived from RAII) is to design classes in such a way,
that all public methods are always callable as soon as such an object exists.
Or in other words: It is bad philosophy to design classes in such a way, that certain methods must be called in a particular order.
Following this philosophy leads to code which avoids null-pointer access.
"ZouLei"
participants (4)
-
Benjamin Lau
-
Peter
-
Steven Watanabe
-
ZouLei