December 6th Thursday (十二月 六日 木曜日)

  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.

 

你可能感兴趣的:(December 6th Thursday (十二月 六日 木曜日))