Plasma Engine  2.0
Loading...
Searching...
No Matches
AllocPolicyHeap.h
1#pragma once
2
3#include <Foundation/Basics.h>
4
9{
10public:
11 PL_ALWAYS_INLINE plAllocPolicyHeap(plAllocator* pParent) {}
12 PL_ALWAYS_INLINE ~plAllocPolicyHeap() = default;
13
14 PL_FORCE_INLINE void* Allocate(size_t uiSize, size_t uiAlign)
15 {
16 // malloc has no alignment guarantees, even though on many systems it returns 16 byte aligned data
17 // if these asserts fail, you need to check what container made the allocation and change it
18 // to use an aligned allocator, e.g. plAlignedAllocatorWrapper
19
20 // unfortunately using PL_ALIGNMENT_MINIMUM doesn't work, because even on 32 Bit systems we try to do allocations with 8 Byte
21 // alignment interestingly, the code that does that, seems to work fine anyway
22 PL_ASSERT_DEBUG(uiAlign <= 8, "This allocator does not guarantee alignments larger than 8. Use an aligned allocator to allocate the desired data type.");
23
24 void* ptr = malloc(uiSize);
25 PL_CHECK_ALIGNMENT(ptr, uiAlign);
26
27 return ptr;
28 }
29
30 PL_FORCE_INLINE void* Reallocate(void* pCurrentPtr, size_t uiCurrentSize, size_t uiNewSize, size_t uiAlign)
31 {
32 void* ptr = realloc(pCurrentPtr, uiNewSize);
33 PL_CHECK_ALIGNMENT(ptr, uiAlign);
34
35 return ptr;
36 }
37
38 PL_ALWAYS_INLINE void Deallocate(void* pPtr)
39 {
40 free(pPtr);
41 }
42
43 PL_ALWAYS_INLINE plAllocator* GetParent() const { return nullptr; }
44};
Default heap memory allocation policy.
Definition AllocPolicyHeap.h:9
Base class for all memory allocators.
Definition Allocator.h:23