]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/PoolMalloc.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / mem / PoolMalloc.h
1 /*
2 * Copyright (C) 1996-2018 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 _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
31 #include "mem/Pool.h"
32
33 #include <stack>
34
35 /// \ingroup MemPoolsAPI
36 class MemPoolMalloc : public MemImplementingAllocator
37 {
38 public:
39 MemPoolMalloc(char const *label, size_t aSize);
40 ~MemPoolMalloc();
41 virtual bool idleTrigger(int shift) const;
42 virtual void clean(time_t maxage);
43
44 /**
45 \param stats Object to be filled with statistical data about pool.
46 \retval Number of objects in use, ie. allocated.
47 */
48 virtual int getStats(MemPoolStats * stats, int accumulate);
49
50 virtual int getInUseCount();
51 protected:
52 virtual void *allocate();
53 virtual void deallocate(void *, bool aggressive);
54 private:
55 std::stack<void *> freelist;
56 };
57
58 #endif /* _MEM_POOL_MALLOC_H_ */
59