--- include/log4cxx/helpers/pool.h 2006/11/09 15:34:58 +++ include/log4cxx/helpers/pool.h 2006/11/22 14:29:44 @@ -36,6 +36,17 @@ char* palloc(size_t length); + /** + * Set the threshold of unused pool memory at which the + * APR allocator starts giving back memory blocks. + * + * @param size number of allowed unused bytes + */ + static void setMaxFreeThreshold(size_t size); + + /** Default threshold for setMaxFreeThreshold() */ + enum { DEFAULT_THRESHOLD = 40960 }; + protected: log4cxx_pool_t* pool; const bool release; --- src/aprinitializer.cpp 2006/11/09 15:34:58 +++ src/aprinitializer.cpp 2006/11/26 23:05:06 @@ -20,6 +20,7 @@ #include #include #include +#include using namespace log4cxx::helpers; using namespace log4cxx; @@ -30,6 +31,7 @@ apr_initialize(); apr_pool_create(&p, NULL); apr_atomic_init(p); + Pool::setMaxFreeThreshold(Pool::DEFAULT_THRESHOLD); startTime = apr_time_now(); #if APR_HAS_THREADS apr_status_t stat = apr_threadkey_private_create(&tlsKey, tlsDestruct, p); --- src/pool.cpp 2006/11/09 15:34:58 +++ src/pool.cpp 2006/11/26 23:05:06 @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -52,3 +53,10 @@ char* Pool::palloc(size_t size) { return (char*) apr_palloc((apr_pool_t*) pool, size); } + +void Pool::setMaxFreeThreshold(size_t size) { + // the allocator may be zero if APR_POOL_DEBUG is defined + apr_allocator_t* allocator = apr_pool_allocator_get(APRInitializer::getRootPool()); + if (allocator) + apr_allocator_max_free_set(allocator, size); +}