]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/AllocatorProxy.h
2 * Copyright (C) 1996-2014 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 #define MEMPROXY_CLASS(CLASS) \
24 static inline Mem::AllocatorProxy &Pool() { \
25 static Mem::AllocatorProxy thePool(#CLASS, sizeof(CLASS)); \
29 void *operator new(size_t byteCount) { \
30 /* derived classes with different sizes must implement their own new */ \
31 assert(byteCount == sizeof(CLASS)); \
32 return Pool().alloc(); \
34 void operator delete(void *address) {Pool().freeOne(address);} \
41 * Support late binding of pool type for allocator agnostic classes
46 AllocatorProxy(char const *aLabel
, size_t const &aSize
):
52 /// Allocate one element from the pool
55 /// Free a element allocated by Mem::AllocatorProxy::alloc()
58 int inUseCount() const;
59 size_t objectSize() const {return size
;}
60 char const * objectType() const {return label
;}
62 MemPoolMeter
const &getMeter() const;
65 * \param stats Object to be filled with statistical data about pool.
66 * \retval Number of objects in use, ie. allocated.
68 int getStats(MemPoolStats
* stats
);
71 MemAllocator
*getAllocator() const;
75 mutable MemAllocator
*theAllocator
;
80 #endif /* _SQUID_SRC_MEM_ALLOCATORPROXY_H */