AllocatorProxy.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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
12// XXX: remove AllocatorProxy.h include from mem/forward.h
13namespace Mem {
14class Allocator;
15class PoolStats;
16}
17
28#define MEMPROXY_CLASS(CLASS) \
29 private: \
30 static inline Mem::AllocatorProxy &Pool() { \
31 static Mem::AllocatorProxy thePool(#CLASS, sizeof(CLASS), false); \
32 return thePool; \
33 } \
34 public: \
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(); \
39 } \
40 void operator delete(void *address) { \
41 if (address) \
42 Pool().freeOne(address); \
43 } \
44 static int UseCount() { return Pool().inUseCount(); } \
45 private:
46
47namespace Mem
48{
49
50class PoolMeter;
51
56{
57public:
58 AllocatorProxy(char const *aLabel, size_t const &aSize, bool doZeroBlocks = true):
59 label(aLabel),
60 size(aSize),
61 theAllocator(nullptr),
62 doZero(doZeroBlocks)
63 {}
64
66 void *alloc();
67
69 void freeOne(void *);
70
71 int inUseCount() const;
72 size_t objectSize() const {return size;}
73 char const * objectType() const {return label;}
74
75 PoolMeter const &getMeter() const;
76
81 size_t getStats(PoolStats &stats);
82
83 void zeroBlocks(bool doIt);
84
86 void relabel(const char * const aLabel);
87
88private:
89 Allocator *getAllocator() const;
90
91 const char *label;
92 size_t size;
94 bool doZero;
95};
96
97} // namespace Mem
98
99#endif /* _SQUID_SRC_MEM_ALLOCATORPROXY_H */
100
void * alloc()
Allocate one element from the pool.
void relabel(const char *const aLabel)
void freeOne(void *)
Free a element allocated by Mem::AllocatorProxy::alloc()
Allocator * getAllocator() const
void zeroBlocks(bool doIt)
int inUseCount() const
AllocatorProxy(char const *aLabel, size_t const &aSize, bool doZeroBlocks=true)
Allocator * theAllocator
char const * objectType() const
size_t getStats(PoolStats &stats)
const char * label
size_t objectSize() const
PoolMeter const & getMeter() const
Memory Management.
Definition: Allocator.h:17
class Ping::pingStats_ stats

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors