]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/PoolMalloc.h
2 * Copyright (C) 1996-2021 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 _MEM_POOL_MALLOC_H_
10 #define _MEM_POOL_MALLOC_H_
13 \defgroup MemPoolsAPI Memory Management (Memory Pool Allocator)
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.
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).
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.
35 /// \ingroup MemPoolsAPI
36 class MemPoolMalloc
: public MemImplementingAllocator
39 MemPoolMalloc(char const *label
, size_t aSize
);
41 virtual bool idleTrigger(int shift
) const;
42 virtual void clean(time_t maxage
);
45 \param stats Object to be filled with statistical data about pool.
46 \retval Number of objects in use, ie. allocated.
48 virtual int getStats(MemPoolStats
* stats
, int accumulate
);
50 virtual int getInUseCount();
52 virtual void *allocate();
53 virtual void deallocate(void *, bool aggressive
);
55 std::stack
<void *> freelist
;
58 #endif /* _MEM_POOL_MALLOC_H_ */