DDNet documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
memheap.h
Go to the documentation of this file.
1
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2
/* If you are missing that file, acquire a complete release at teeworlds.com. */
3
#ifndef ENGINE_SHARED_MEMHEAP_H
4
#define ENGINE_SHARED_MEMHEAP_H
5
6
#include <cstddef>
7
#include <new>
8
#include <utility>
9
10
class
CHeap
11
{
12
struct
CChunk
13
{
14
char
*
m_pMemory
;
15
char
*
m_pCurrent
;
16
char
*
m_pEnd
;
17
CChunk
*
m_pNext
;
18
};
19
23
static
constexpr
size_t
CHUNK_SIZE
= 1025 * 64;
24
25
CChunk
*
m_pCurrent
;
26
27
void
Clear
();
28
void
NewChunk
(
size_t
ChunkSize);
29
void
*
AllocateFromChunk
(
size_t
Size,
size_t
Alignment);
30
31
public
:
32
CHeap
();
33
~CHeap
();
34
void
Reset
();
35
void
*
Allocate
(
size_t
Size,
size_t
Alignment =
alignof
(std::max_align_t));
36
const
char
*
StoreString
(
const
char
*pSrc);
37
38
template
<
typename
T,
typename
... TArgs>
39
T *
Allocate
(TArgs &&...Args)
40
{
41
return
new
(
Allocate
(
sizeof
(T),
alignof
(T))) T(std::forward<TArgs>(Args)...);
42
}
43
};
44
45
#endif
CHeap::Clear
void Clear()
Definition
memheap.cpp:64
CHeap::Allocate
T * Allocate(TArgs &&...Args)
Definition
memheap.h:39
CHeap::AllocateFromChunk
void * AllocateFromChunk(size_t Size, size_t Alignment)
Definition
memheap.cpp:29
CHeap::CHeap
CHeap()
Definition
memheap.cpp:46
CHeap::Reset
void Reset()
Definition
memheap.cpp:57
CHeap::NewChunk
void NewChunk(size_t ChunkSize)
Definition
memheap.cpp:12
CHeap::Allocate
void * Allocate(size_t Size, size_t Alignment=alignof(std::max_align_t))
Definition
memheap.cpp:75
CHeap::m_pCurrent
CChunk * m_pCurrent
Definition
memheap.h:25
CHeap::StoreString
const char * StoreString(const char *pSrc)
Definition
memheap.cpp:91
CHeap::CHUNK_SIZE
static constexpr size_t CHUNK_SIZE
Definition
memheap.h:23
CHeap::CChunk
Definition
memheap.h:13
CHeap::CChunk::m_pCurrent
char * m_pCurrent
Definition
memheap.h:15
CHeap::CChunk::m_pMemory
char * m_pMemory
Definition
memheap.h:14
CHeap::CChunk::m_pEnd
char * m_pEnd
Definition
memheap.h:16
CHeap::CChunk::m_pNext
CChunk * m_pNext
Definition
memheap.h:17
src
engine
shared
memheap.h
Generated by
1.18.0