]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
mempools-nozero part 4: do not zero out MEMPROXY_CLASS pools
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 24 Aug 2015 17:53:25 +0000 (19:53 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 24 Aug 2015 17:53:25 +0000 (19:53 +0200)
src/mem/AllocatorProxy.cc
src/mem/AllocatorProxy.h

index 4fcd1bda0d0b739dfca2a949a287a941ccf2237a..6ab74281cee2dfbfddcf09942f1240f869464422 100644 (file)
@@ -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
 {
index c6ea9a7f9e491f2c70e3eab6e311e3b24e4c68ab..d4303cb214fb05cbb8f0bd8340f6fd2ac837bf38 100644 (file)
@@ -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