MemAllocator *
Mem::AllocatorProxy::getAllocator() const
{
- if (!theAllocator)
+ if (!theAllocator) {
theAllocator = MemPools::GetInstance().create(objectType(), size);
+ theAllocator->zeroBlocks(doZero);
+ }
return theAllocator;
}
return memPoolInUseCount(theAllocator);
}
+void
+Mem::AllocatorProxy::zeroBlocks(bool doIt)
+{
+ getAllocator()->zeroBlocks(doIt);
+}
+
MemPoolMeter const &
Mem::AllocatorProxy::getMeter() const
{
*
* 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: \
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
*/
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