Plasma Engine  2.0
Loading...
Searching...
No Matches
PageAllocator_Posix.h
1#include <Foundation/Memory/MemoryTracker.h>
2#include <Foundation/Memory/PageAllocator.h>
3#include <Foundation/System/SystemInformation.h>
4#include <Foundation/Time/Time.h>
5
6// static
7void* plPageAllocator::AllocatePage(size_t uiSize)
8{
9 plTime fAllocationTime = plTime::Now();
10
11 void* ptr = nullptr;
13 const int res = posix_memalign(&ptr, uiAlign, uiSize);
14 PL_ASSERT_DEBUG(res == 0, "Failed to align pointer");
15 PL_IGNORE_UNUSED(res);
16
17 PL_CHECK_ALIGNMENT(ptr, uiAlign);
18
19 if constexpr (plAllocatorTrackingMode::Default >= plAllocatorTrackingMode::AllocationStats)
20 {
21 plMemoryTracker::AddAllocation(plPageAllocator::GetId(), plAllocatorTrackingMode::Default, ptr, uiSize, uiAlign, plTime::Now() - fAllocationTime);
22 }
23
24 return ptr;
25}
26
27// static
28void plPageAllocator::DeallocatePage(void* ptr)
29{
30 if constexpr (plAllocatorTrackingMode::Default >= plAllocatorTrackingMode::AllocationStats)
31 {
32 plMemoryTracker::RemoveAllocation(plPageAllocator::GetId(), ptr);
33 }
34
35 free(ptr);
36}
static const plSystemInformation & Get()
Allows access to the current system configuration.
Definition SystemInformation.h:131
plUInt32 GetMemoryPageSize() const
Returns the size of a memory page in bytes.
Definition SystemInformation.h:106
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
static plTime Now()
Gets the current time.
Definition Time_Posix.h:12