Grindstone Game Engine
v0.2.0
An open source game engine and toolkit.
Toggle main menu visibility
Loading...
Searching...
No Matches
LinearAllocator.hpp
1
#pragma once
2
3
#include <stdint.h>
4
5
6
namespace
Grindstone::Memory::Allocators {
14
class
LinearAllocator
{
15
public
:
16
~LinearAllocator
();
17
18
void
Initialize(
void
* ownedMemory,
size_t
size);
19
bool
Initialize(
size_t
size);
20
void
* Allocate(
size_t
size);
21
void
Clear();
22
void
ClearAndZero();
23
void
Destroy();
24
25
template
<
typename
T,
typename
... Args>
26
T* Allocate(Args&&... params) {
27
T* ptr =
static_cast<
T*
>
(Allocate(
sizeof
(T)));
28
if
(ptr !=
nullptr
) {
29
// Call the constructor on the newly allocated memory
30
new
(ptr) T(std::forward<Args>(params)...);
31
}
32
33
return
ptr;
34
}
35
36
template
<
typename
T>
37
T* AllocateWithoutConstructor() {
38
return
static_cast<
T*
>
(Allocate(
sizeof
(T)));
39
}
40
41
private
:
42
size_t
totalMemorySize;
43
size_t
usedSize;
44
45
void
* memory;
46
bool
hasAllocatedOwnMemory;
47
};
48
}
Grindstone::Memory::Allocators::LinearAllocator
A linear allocator where memory can only be deallocated when the entire allocator is cleared.
Definition
LinearAllocator.hpp:14
sources
code
Common
Memory
Allocators
LinearAllocator.hpp
Generated by
1.17.0