Plasma Engine  2.0
Loading...
Searching...
No Matches
LinearAllocator.h
1#pragma once
2
3#include <Foundation/Containers/DynamicArray.h>
4#include <Foundation/Containers/HashTable.h>
5#include <Foundation/Memory/AllocatorWithPolicy.h>
6#include <Foundation/Memory/Policies/AllocPolicyLinear.h>
7#include <Foundation/Threading/Lock.h>
8#include <Foundation/Threading/Mutex.h>
9
10template <plAllocatorTrackingMode TrackingMode = plAllocatorTrackingMode::Default, bool OverwriteMemoryOnReset = false>
11class plLinearAllocator : public plAllocatorWithPolicy<plAllocPolicyLinear<OverwriteMemoryOnReset>, TrackingMode>
12{
14
15public:
18
19 virtual void* Allocate(size_t uiSize, size_t uiAlign, plMemoryUtils::DestructorFunction destructorFunc) override;
20 virtual void Deallocate(void* pPtr) override;
21
24 void Reset();
25
26private:
27 struct DestructData
28 {
29 PL_DECLARE_POD_TYPE();
30
31 plMemoryUtils::DestructorFunction m_Func;
32 void* m_Ptr;
33 };
34
35 plMutex m_Mutex;
36 plDynamicArray<DestructData> m_DestructData;
37 plHashTable<void*, plUInt32> m_PtrToDestructDataIndexTable;
38};
39
40#include <Foundation/Memory/Implementation/LinearAllocator_inl.h>
This policy implements a linear allocator that can only grow and at some point all allocations gets r...
Definition AllocPolicyLinear.h:12
Base class for all memory allocators.
Definition Allocator.h:23
Policy based allocator implementation of the plAllocator interface.
Definition AllocatorWithPolicy.h:19
Definition DynamicArray.h:81
Definition HashTable.h:333
Definition LinearAllocator.h:12
void Reset()
Resets the allocator freeing all memory.
Definition LinearAllocator_inl.h:58
virtual void * Allocate(size_t uiSize, size_t uiAlign, plMemoryUtils::DestructorFunction destructorFunc) override
Interface, do not use this directly, always use the new/delete macros below.
Definition LinearAllocator_inl.h:16
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34