From: Francesco Chemolli Date: Thu, 7 Apr 2011 13:26:54 +0000 (+0200) Subject: Enable MemBlob to use the services of MemPools. X-Git-Tag: take06~27^2~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=835f22bbb05537c998bf4f293de3ebfc8f560b73;p=thirdparty%2Fsquid.git Enable MemBlob to use the services of MemPools. Ensure that MemBlobs use MemPools manage memory areas, and remove duplication of code with MemPools. --- diff --git a/src/MemBlob.cc b/src/MemBlob.cc index 7da391d232..6316d02e7d 100644 --- a/src/MemBlob.cc +++ b/src/MemBlob.cc @@ -32,16 +32,14 @@ #include "config.h" #include "base/TextException.h" #include "Debug.h" +#include "Mem.h" #include "MemBlob.h" +#include "protos.h" + #if HAVE_IOSTREAM #include #endif -#define MEMBLOB_USES_MEM_POOLS 0 - -#if MEMBLOB_USES_MEM_POOLS -#include "protos.h" -#endif MemBlobStats MemBlob::Stats; InstanceIdDefinitions(MemBlob, "blob"); @@ -90,13 +88,8 @@ MemBlob::MemBlob(const char *buffer, const MemBlob::size_type bufSize) : MemBlob::~MemBlob() { -#if MEMBLOB_USES_MEM_POOLS - //no mempools for now - // \todo reinstate mempools use - memFreeString(capacity,mem); -#else - xfree(mem); -#endif + if (mem || capacity) + memFreeString(capacity,mem); Stats.liveBytes -= capacity; --Stats.live; @@ -106,45 +99,16 @@ MemBlob::~MemBlob() << " size=" << size); } -/** - * Given the requested minimum size, return a rounded allocation size - * for the backing store. - * This is a stopgap call, this job is eventually expected to be handled - * by MemPools via memAllocString. - */ -MemBlob::size_type -MemBlob::calcAllocSize(const size_type sz) const -{ - if (sz <= 36) return 36; - if (sz <= 128) return 128; - if (sz <= 512) return 512; - if (sz <= 4096) return RoundTo(sz, 512); - // XXX: recover squidSystemPageSize functionality. It's easy for - // the main squid, harder for tests -#if 0 - return RoundTo(sz, squidSystemPageSize); -#else - return RoundTo(sz, 4096); -#endif -} - /** Allocate an available space area of at least minSize bytes in size. * Must be called by constructors and only by constructors. */ void MemBlob::memAlloc(const size_type minSize) { - size_t actualAlloc = calcAllocSize(minSize); + size_t actualAlloc = minSize; Must(!mem); -#if MEMBLOB_USES_MEM_POOLS - // XXX: for now, do without mempools. In order to do it, MemPools - // need to be singletons so that initialization order can be enforced - mem = static_cast(memAllocString(minSize, &actualAlloc)); -#else - // \todo reinstate mempools use - mem = static_cast(xmalloc(actualAlloc)); -#endif + mem = static_cast(memAllocString(actualAlloc, &actualAlloc)); Must(mem); capacity = actualAlloc; diff --git a/src/MemBlob.h b/src/MemBlob.h index 8a25bd4b77..9cdbd0a2df 100644 --- a/src/MemBlob.h +++ b/src/MemBlob.h @@ -122,7 +122,6 @@ private: static MemBlobStats Stats; ///< class-wide statistics void memAlloc(const size_type memSize); - size_type calcAllocSize(const size_type minSize) const; /// whether the offset points to the end of the used area bool isAppendOffset(const size_type off) const { return off == size; }