The apr_pool_cleanup_register() provided by APR is for managing memory, as well as a few other basic resources
such as files, sockets, and mutexes.
class poolclass {
private:
apr_pool_t* pool;
public:
poolclass(apr_pool_t* p) : pool(p) {
apr_pool_cleanup_register(pool, (void*)this, myclassCleanup, apr_pool_cleanup_null);
}
virtual ~poolclass(){
apr_pool_cleanup_kill(pool, (void*)this, myclassCleanup);
}
};
You can also streamline the kill the cleanup and free by running the cleanup and unregistering it with
the pool using a single function:
apr_pool_cleanup_run(pool, my_res, my_res_free);
In Apache, there are four pool structures corresponding to different types of resource.
* The request pool, with the lifetime of an HTTP request (request->pool)
* The process pool, with the lifetime of a server process (process->pool)
* The connection pool, with the lifetime of a TCP connection (connection->pool)
* The configuration pool (process->pconf)
The fourth is also associated with the process, but differs from the process pool in that it is cleared
whenever Apache rereads its configuration.
The process pool is suitable for long-lived resources, such as those that are initialized at server start-up.
The request pool is suitable for transient resources used to process a single request.
The connection pool has the lifetime of a connection, which normally consists of one or more requests. This
pool is useful for transient resources that cannot be associated with a request--most notably, in a connection-
level filter, where the request_rec structure is undefined, or in a non-HTTP protocol handler.
In addition to these standard pools, special-purpose pools may be created for other purposes, such as configuration
and logging, or may be created privately by modules for their own use.
such as files, sockets, and mutexes.
class poolclass {
private:
apr_pool_t* pool;
public:
poolclass(apr_pool_t* p) : pool(p) {
apr_pool_cleanup_register(pool, (void*)this, myclassCleanup, apr_pool_cleanup_null);
}
virtual ~poolclass(){
apr_pool_cleanup_kill(pool, (void*)this, myclassCleanup);
}
};
You can also streamline the kill the cleanup and free by running the cleanup and unregistering it with
the pool using a single function:
apr_pool_cleanup_run(pool, my_res, my_res_free);
In Apache, there are four pool structures corresponding to different types of resource.
* The request pool, with the lifetime of an HTTP request (request->pool)
* The process pool, with the lifetime of a server process (process->pool)
* The connection pool, with the lifetime of a TCP connection (connection->pool)
* The configuration pool (process->pconf)
The fourth is also associated with the process, but differs from the process pool in that it is cleared
whenever Apache rereads its configuration.
The process pool is suitable for long-lived resources, such as those that are initialized at server start-up.
The request pool is suitable for transient resources used to process a single request.
The connection pool has the lifetime of a connection, which normally consists of one or more requests. This
pool is useful for transient resources that cannot be associated with a request--most notably, in a connection-
level filter, where the request_rec structure is undefined, or in a non-HTTP protocol handler.
In addition to these standard pools, special-purpose pools may be created for other purposes, such as configuration
and logging, or may be created privately by modules for their own use.
本文介绍了Apache Portable Runtime (APR)中提供的apr_pool_cleanup_register()函数,该函数用于管理内存和其他基本资源如文件、套接字和互斥锁。此外,文章还详细解释了Apache中的四种不同类型的资源池:请求池、进程池、连接池和配置池,并讨论了它们各自的用途。
6万+

被折叠的 条评论
为什么被折叠?



