AllocatorProxy.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef _SQUID_SRC_MEM_ALLOCATORPROXY_H
10#define _SQUID_SRC_MEM_ALLOCATORPROXY_H
11
12class MemAllocator;
13class MemPoolStats;
14class MemPoolMeter;
15
26#define MEMPROXY_CLASS(CLASS) \
27 private: \
28 static inline Mem::AllocatorProxy &Pool() { \
29 static Mem::AllocatorProxy thePool(#CLASS, sizeof(CLASS), false); \
30 return thePool; \
31 } \
32 public: \
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(); \
37 } \
38 void operator delete(void *address) { \
39 if (address) \
40 Pool().freeOne(address); \
41 } \
42 static int UseCount() { return Pool().inUseCount(); } \
43 private:
44
45namespace Mem
46{
47
52{
53public:
54 AllocatorProxy(char const *aLabel, size_t const &aSize, bool doZeroBlocks = true):
55 label(aLabel),
56 size(aSize),
57 theAllocator(nullptr),
58 doZero(doZeroBlocks)
59 {}
60
62 void *alloc();
63
65 void freeOne(void *);
66
67 int inUseCount() const;
68 size_t objectSize() const {return size;}
69 char const * objectType() const {return label;}
70
71 MemPoolMeter const &getMeter() const;
72
78
79 void zeroBlocks(bool doIt);
80
81private:
83
84 const char *label;
85 size_t size;
87 bool doZero;
88};
89
90} // namespace Mem
91
92#endif /* _SQUID_SRC_MEM_ALLOCATORPROXY_H */
93
void * alloc()
Allocate one element from the pool.
void freeOne(void *)
Free a element allocated by Mem::AllocatorProxy::alloc()
void zeroBlocks(bool doIt)
int inUseCount() const
AllocatorProxy(char const *aLabel, size_t const &aSize, bool doZeroBlocks=true)
MemAllocator * getAllocator() const
char const * objectType() const
const char * label
size_t objectSize() const
MemAllocator * theAllocator
int getStats(MemPoolStats *stats)
MemPoolMeter const & getMeter() const
Memory Management.
class Ping::pingStats_ stats

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors