]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/AllocatorProxy.h
b3b8fc3b361695b2970e63311f0ca64d8c69e24c
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef _SQUID_SRC_MEM_ALLOCATORPROXY_H
10 #define _SQUID_SRC_MEM_ALLOCATORPROXY_H
19 * Pool and account the memory used for the CLASS object.
20 * This macro is intended for use within the declaration of a class.
22 * The memory block allocated by operator new is not zeroed; it is the
23 * responsibility of users to ensure that constructors correctly
24 * initialize all data members.
26 #define MEMPROXY_CLASS(CLASS) \
28 static inline Mem::AllocatorProxy &Pool() { \
29 static Mem::AllocatorProxy thePool(#CLASS, sizeof(CLASS), false); \
33 void *operator new(size_t byteCount) { \
34 /* derived classes with different sizes must implement their own new */ \
35 assert(byteCount == sizeof(CLASS)); \
36 return Pool().alloc(); \
38 void operator delete(void *address) { \
40 Pool().freeOne(address); \
42 static int UseCount() { return Pool().inUseCount(); } \
49 * Support late binding of pool type for allocator agnostic classes
54 AllocatorProxy(char const *aLabel
, size_t const &aSize
, bool doZeroBlocks
= true):
57 theAllocator(nullptr),
61 /// Allocate one element from the pool
64 /// Free a element allocated by Mem::AllocatorProxy::alloc()
67 int inUseCount() const;
68 size_t objectSize() const {return size
;}
69 char const * objectType() const {return label
;}
71 MemPoolMeter
const &getMeter() const;
74 * \param stats Object to be filled with statistical data about pool.
75 * \retval Number of objects in use, ie. allocated.
77 int getStats(MemPoolStats
* stats
);
79 void zeroBlocks(bool doIt
);
82 MemAllocator
*getAllocator() const;
86 mutable MemAllocator
*theAllocator
;
92 #endif /* _SQUID_SRC_MEM_ALLOCATORPROXY_H */