]>
Commit | Line | Data |
---|---|---|
5c193dec AJ |
1 | /* |
2 | * Copyright (C) 1996-2014 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 | ||
8cfaefed HN |
9 | #ifndef _MEM_POOL_MALLOC_H_ |
10 | #define _MEM_POOL_MALLOC_H_ | |
11 | ||
12 | /** | |
13 | \defgroup MemPoolsAPI Memory Management (Memory Pool Allocator) | |
14 | \ingroup Components | |
15 | * | |
16 | *\par | |
17 | * MemPools are a pooled memory allocator running on top of malloc(). It's | |
18 | * purpose is to reduce memory fragmentation and provide detailed statistics | |
19 | * on memory consumption. | |
20 | * | |
21 | \par | |
22 | * Preferably all memory allocations in Squid should be done using MemPools | |
23 | * or one of the types built on top of it (i.e. cbdata). | |
24 | * | |
25 | \note Usually it is better to use cbdata types as these gives you additional | |
26 | * safeguards in references and typechecking. However, for high usage pools where | |
27 | * the cbdata functionality of cbdata is not required directly using a MemPool | |
28 | * might be the way to go. | |
29 | */ | |
30 | ||
ed6e9fb9 | 31 | #include "mem/Pool.h" |
8cfaefed | 32 | |
0f87a483 FC |
33 | #include <stack> |
34 | ||
8cfaefed HN |
35 | /// \ingroup MemPoolsAPI |
36 | class MemPoolMalloc : public MemImplementingAllocator | |
37 | { | |
38 | public: | |
39 | MemPoolMalloc(char const *label, size_t aSize); | |
2be7332c | 40 | ~MemPoolMalloc(); |
8cfaefed HN |
41 | virtual bool idleTrigger(int shift) const; |
42 | virtual void clean(time_t maxage); | |
43 | ||
44 | /** | |
f53969cc SM |
45 | \param stats Object to be filled with statistical data about pool. |
46 | \retval Number of objects in use, ie. allocated. | |
8cfaefed HN |
47 | */ |
48 | virtual int getStats(MemPoolStats * stats, int accumulate); | |
49 | ||
50 | virtual int getInUseCount(); | |
51 | protected: | |
52 | virtual void *allocate(); | |
2be7332c | 53 | virtual void deallocate(void *, bool aggressive); |
8cfaefed | 54 | private: |
0f87a483 | 55 | std::stack<void *> freelist; |
8cfaefed HN |
56 | }; |
57 | ||
8cfaefed | 58 | #endif /* _MEM_POOL_MALLOC_H_ */ |
f53969cc | 59 |