virtual char const *objectType() const;
virtual size_t objectSize() const = 0;
virtual int getInUseCount() = 0;
- void zeroOnPush(bool doIt);
+ void zeroBlocks(bool doIt) {doZero = doIt;}
int inUseCount();
/**
static size_t RoundedSize(size_t minSize);
protected:
- bool doZeroOnPush;
+ /** Whether to zero memory on initial allocation and on return to the pool.
+ *
+ * We do this on some pools because many object constructors are/were incomplete
+ * and we are afraid some code may use the object after free.
+ * These probems are becoming less common, so when possible set this to false.
+ */
+ bool doZero;
private:
const char *label;
return pools_inuse;
}
-MemAllocator::MemAllocator(char const *aLabel) : doZeroOnPush(true), label(aLabel)
+MemAllocator::MemAllocator(char const *aLabel) : doZero(true), label(aLabel)
{
}
--MemPools::GetInstance().poolCount;
}
-void
-MemAllocator::zeroOnPush(bool doIt)
-{
- doZeroOnPush = doIt;
-}
-
MemPoolMeter const &
MemImplementingAllocator::getMeter() const
{
next = NULL;
pool = aPool;
- objCache = xcalloc(1, pool->chunk_size);
+ if (pool->doZero)
+ objCache = xcalloc(1, pool->chunk_size);
+ else
+ objCache = xmalloc(pool->chunk_size);
+
freeList = objCache;
void **Free = (void **)freeList;
* not really need to be cleared.. There was a condition based on
* the object size here, but such condition is not safe.
*/
- if (doZeroOnPush)
+ if (doZero)
memset(obj, 0, obj_size);
Free = (void **)obj;
*Free = freeCache;
memMeterDec(meter.idle);
++saved_calls;
} else {
- obj = xcalloc(1, obj_size);
+ if (doZero)
+ obj = xcalloc(1, obj_size);
+ else
+ obj = xmalloc(obj_size);
memMeterInc(meter.alloc);
}
memMeterInc(meter.inuse);
xfree(obj);
memMeterDec(meter.alloc);
} else {
- if (doZeroOnPush)
+ if (doZero)
memset(obj, 0, obj_size);
memMeterInc(meter.idle);
freelist.push_back(obj);
void memFreeBuf(size_t size, void *);
FREE *memFreeBufFunc(size_t size);
int memInUse(mem_type);
-void memDataInit(mem_type, const char *, size_t, int, bool zeroOnPush = true);
+void memDataInit(mem_type, const char *, size_t, int, bool doZero = true);
void memCheckInit(void);
void memConfigure(void);
* Relies on Mem::Init() having been called beforehand.
*/
void
-memDataInit(mem_type type, const char *name, size_t size, int max_pages_notused, bool zeroOnPush)
+memDataInit(mem_type type, const char *name, size_t size, int max_pages_notused, bool doZero)
{
assert(name && size);
return;
MemPools[type] = memPoolCreate(name, size);
- MemPools[type]->zeroOnPush(zeroOnPush);
+ MemPools[type]->zeroBlocks(doZero);
}
/* find appropriate pool and use it (pools always init buffer with 0s) */
/** Lastly init the string pools. */
for (i = 0; i < mem_str_pool_count; ++i) {
StrPools[i].pool = memPoolCreate(StrPoolsAttrs[i].name, StrPoolsAttrs[i].obj_size);
- StrPools[i].pool->zeroOnPush(false);
+ StrPools[i].pool->zeroBlocks(false);
if (StrPools[i].pool->objectSize() != StrPoolsAttrs[i].obj_size)
debugs(13, DBG_IMPORTANT, "Notice: " << StrPoolsAttrs[i].name << " is " << StrPools[i].pool->objectSize() << " bytes instead of requested " << StrPoolsAttrs[i].obj_size << " bytes");