]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mem/minimal.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / mem / minimal.cc
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 #include "squid.h"
10 #include "mem/AllocatorProxy.h"
11 #include "mem/forward.h"
12
13 /// The number of currently alive objects (poor man's meter.alloc=meter.inuse).
14 /// Technically, this is supposed to be a per-allocator statistics, but
15 /// AllocatorProxy is not a Mem::Allocator so we maintain a global counter
16 /// instead. We probably do not have to maintain this statistics at all.
17 static int Alive = 0;
18
19 void *
20 Mem::AllocatorProxy::alloc()
21 {
22 const auto memory = doZero ? xcalloc(1, size) : xmalloc(size);
23 ++Alive;
24 return memory;
25 }
26
27 void
28 Mem::AllocatorProxy::freeOne(void *memory) {
29 xfree(memory);
30 --Alive;
31 }
32
33 int
34 Mem::AllocatorProxy::inUseCount() const
35 {
36 return Alive;
37 }
38
39 size_t
40 Mem::AllocatorProxy::getStats(PoolStats &)
41 {
42 return Alive;
43 }
44
45 void *
46 memAllocBuf(const size_t netSize, size_t * const grossSize)
47 {
48 *grossSize = netSize;
49 return xcalloc(1, netSize);
50 }
51
52 void *
53 memReallocBuf(void * const oldBuf, const size_t netSize, size_t * const grossSize)
54 {
55 *grossSize = netSize;
56 return xrealloc(oldBuf, netSize);
57 }
58
59 void
60 memFree(void *memory, int)
61 {
62 xfree(memory);
63 }
64
65 void *
66 memAllocString(const size_t netSize, size_t * const grossSize)
67 {
68 return memAllocBuf(netSize, grossSize);
69 }
70
71 void
72 memFreeString(size_t, void *memory)
73 {
74 xfree(memory);
75 }
76
77 void *
78 memAllocRigid(const size_t netSize)
79 {
80 return xmalloc(netSize);
81 }
82
83 void
84 memFreeBuf(size_t, void * const buf)
85 {
86 xfree(buf);
87 }
88
89 static void
90 myFree(void * const buf)
91 {
92 xfree(buf);
93 }
94
95 FREE *
96 memFreeBufFunc(size_t)
97 {
98 return &myFree;
99 }
100