From 341d719cd3058c49281a7eae08f8b17484cbe4f1 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Mon, 24 Aug 2015 19:53:25 +0200 Subject: [PATCH] mempools-nozero part 4: do not zero out MEMPROXY_CLASS pools --- src/mem/AllocatorProxy.cc | 10 +++++++++- src/mem/AllocatorProxy.h | 14 +++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/mem/AllocatorProxy.cc b/src/mem/AllocatorProxy.cc index 4fcd1bda0d..6ab74281ce 100644 --- a/src/mem/AllocatorProxy.cc +++ b/src/mem/AllocatorProxy.cc @@ -28,8 +28,10 @@ Mem::AllocatorProxy::freeOne(void *address) MemAllocator * Mem::AllocatorProxy::getAllocator() const { - if (!theAllocator) + if (!theAllocator) { theAllocator = MemPools::GetInstance().create(objectType(), size); + theAllocator->zeroBlocks(doZero); + } return theAllocator; } @@ -42,6 +44,12 @@ Mem::AllocatorProxy::inUseCount() const return memPoolInUseCount(theAllocator); } +void +Mem::AllocatorProxy::zeroBlocks(bool doIt) +{ + getAllocator()->zeroBlocks(doIt); +} + MemPoolMeter const & Mem::AllocatorProxy::getMeter() const { diff --git a/src/mem/AllocatorProxy.h b/src/mem/AllocatorProxy.h index c6ea9a7f9e..d4303cb214 100644 --- a/src/mem/AllocatorProxy.h +++ b/src/mem/AllocatorProxy.h @@ -18,11 +18,15 @@ class MemPoolMeter; * * Pool and account the memory used for the CLASS object. * This macro is intended for use within the declaration of a class. + * + * The memory block allocated by operator new is not zeroed; it is the + * responsibility of users to ensure that constructors correctly + * initialize all data members. */ #define MEMPROXY_CLASS(CLASS) \ private: \ static inline Mem::AllocatorProxy &Pool() { \ - static Mem::AllocatorProxy thePool(#CLASS, sizeof(CLASS)); \ + static Mem::AllocatorProxy thePool(#CLASS, sizeof(CLASS), false); \ return thePool; \ } \ public: \ @@ -43,10 +47,11 @@ namespace Mem class AllocatorProxy { public: - AllocatorProxy(char const *aLabel, size_t const &aSize): + AllocatorProxy(char const *aLabel, size_t const &aSize, bool doZeroBlocks = true): label(aLabel), size(aSize), - theAllocator(NULL) + theAllocator(nullptr), + doZero(doZeroBlocks) {} /// Allocate one element from the pool @@ -67,12 +72,15 @@ public: */ int getStats(MemPoolStats * stats); + void zeroBlocks(bool doIt); + private: MemAllocator *getAllocator() const; const char *label; size_t size; mutable MemAllocator *theAllocator; + bool doZero; }; } // namespace Mem -- 2.47.2