-- A lot of things are summarized after reading books and learning from the Internet:
Simple and practical things have been used many times, and I don't know whether it was raiI --- resource acquire is initial.
Originated from the idea of Bjarne stroustrup, founder of C ++, it mainly solves Resource Management (mainly release issues). Compared with Java, C ++ releases resources, more needs to be manually processed by programmers.
Therefore, you can use the object life cycle (the object on the stack) to manage resources at the beginning and end of the object Life Cycle (any resource can be a connection or a piece of memory ), object creation (initialization) and object extinction (release resources );
Most of the time, I also get used to calling the stack object proxy, which is just an intermediary for managing specific resources. In the following example, an autolock instance is only a proxy for the system resource in the critical section, the resource to be managed is a critical zone.
Class autolock
{
Public:
Autolock ()
{
Init *** (mcriticalsection) // initialize the critical section
}
~ Autolock ()
{
Delete ** (mcriticalsection) // deletes the critical section.
}
Void lock ()
{
Enter ** () // enter the critical section
}
Void unlock ()
{
Leave *** () // introduces the critical section
}
Critical_section mcriticalsection;
};
If an object autolock mylock is within its lifecycle, it is responsible for managing and eliminating the critical zone resources of the cause.
To some extent, it solves some resource management troubles.