CookMem 1.4.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
mallocarena.h
1/*
2 * Copyright (c) 2021-2026 Heng Yuan
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef COOK_MALLOC_MEM_ARENA_H
17#define COOK_MALLOC_MEM_ARENA_H
18
19#include <cstdlib>
20
21#include "arena.h"
22#include "config.h"
23
24namespace cookmem
25{
26
35{
36public:
45 : m_minSize (minSize)
46 {
47 }
48
57 void*
58 getSegment (std::size_t& size)
59 {
60 if (size < m_minSize)
61 {
62 size = m_minSize;
63 }
64 return malloc (size);
65 }
66
74 bool
75 freeSegment (void* ptr, std::size_t)
76 {
77 free (ptr);
78 return false;
79 }
80
85 void
87 {
88 }
89
90private:
91 std::size_t m_minSize;
92};
93
94} // namespace cookmem
95
96#endif // COOK_MALLOC_MEM_ARENA_H
Definition mallocarena.h:35
MallocArena(std::size_t minSize=DEFAULT_MIN_SEGMENT_SIZE)
Definition mallocarena.h:44
void releaseAll()
Definition mallocarena.h:86
void * getSegment(std::size_t &size)
Definition mallocarena.h:58
bool freeSegment(void *ptr, std::size_t)
Definition mallocarena.h:75
Definition allocator.h:39
Definition allocator.h:29
const std::size_t DEFAULT_MIN_SEGMENT_SIZE
Definition config.h:52