]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/AllocatorProxy.h
2 * Copyright (C) 1996-2022 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
12 // XXX: remove AllocatorProxy.h include from mem/forward.h
21 * Pool and account the memory used for the CLASS object.
22 * This macro is intended for use within the declaration of a class.
24 * The memory block allocated by operator new is not zeroed; it is the
25 * responsibility of users to ensure that constructors correctly
26 * initialize all data members.
28 #define MEMPROXY_CLASS(CLASS) \
30 static inline Mem::AllocatorProxy &Pool() { \
31 static Mem::AllocatorProxy thePool(#CLASS, sizeof(CLASS), false); \
35 void *operator new(size_t byteCount) { \
36 /* derived classes with different sizes must implement their own new */ \
37 assert(byteCount == sizeof(CLASS)); \
38 return Pool().alloc(); \
40 void operator delete(void *address) { \
42 Pool().freeOne(address); \
44 static int UseCount() { return Pool().inUseCount(); } \
53 * Support late binding of pool type for allocator agnostic classes
58 AllocatorProxy(char const *aLabel
, size_t const &aSize
, bool doZeroBlocks
= true):
61 theAllocator(nullptr),
65 /// Allocate one element from the pool
68 /// Free a element allocated by Mem::AllocatorProxy::alloc()
71 int inUseCount() const;
72 size_t objectSize() const {return size
;}
73 char const * objectType() const {return label
;}
75 PoolMeter
const &getMeter() const;
78 * \param stats Object to be filled with statistical data about pool.
79 * \retval Number of objects in use, ie. allocated.
81 size_t getStats(PoolStats
&stats
);
83 void zeroBlocks(bool doIt
);
86 Allocator
*getAllocator() const;
90 mutable Allocator
*theAllocator
;
96 #endif /* _SQUID_SRC_MEM_ALLOCATORPROXY_H */