One case is a pool of easy curl objects:
CURL *WebResponse::getFromPool()
{
// all actions with the pool must be locked
boost::mutex::scoped_lock lock(poolMutex);
if (curlPool.empty())
{
CURL *pCurl = curl_easy_init();
if (!pCurl)
throw ("allocation failure CURL");
return pCurl;
}
CURL *p = curlPool.front();
curlPool.pop_front();
return p;
}
void WebResponse::putBackInPool(CURL *pCurl)
{
// all actions with the pool must be locked
boost::mutex::scoped_lock lock(poolMutex);
curlPool.push_back(pCurl);
}
The other a pool of libmemcached objects. This should be an interesting use of templates. I'll post what I come up with soon.