UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
SystemAllocator.h
1#pragma once
2#include <UnCompute/Memory/IAllocator.h>
3
4namespace UN
5{
8 {
9 static SystemAllocator m_Instance;
10
11 public:
12 void* Allocate(USize size, USize alignment) override;
13 void Deallocate(void* pointer) override;
14 [[nodiscard]] const char* GetName() const override;
15
17 inline static SystemAllocator* Get()
18 {
19 return &m_Instance;
20 }
21 };
22
23 inline SystemAllocator SystemAllocator::m_Instance;
24
25 inline void* SystemAllocator::Allocate(USize size, USize alignment)
26 {
27 return UN_ALIGNED_MALLOC(size, alignment);
28 }
29
30 inline void SystemAllocator::Deallocate(void* pointer)
31 {
32 return UN_ALIGNED_FREE(pointer);
33 }
34
35 inline const char* SystemAllocator::GetName() const
36 {
37 return "System allocator";
38 }
39} // namespace UN
An interface for memory allocators.
Definition: IAllocator.h:8
This allocator uses platform-specific aligned versions of malloc() and free().
Definition: SystemAllocator.h:8
const char * GetName() const override
Get debug name of the allocator.
Definition: SystemAllocator.h:35
void Deallocate(void *pointer) override
Deallocate memory.
Definition: SystemAllocator.h:30
static SystemAllocator * Get()
Get global static instance of the system allocator.
Definition: SystemAllocator.h:17
void * Allocate(USize size, USize alignment) override
Allocate memory.
Definition: SystemAllocator.h:25