4#include "../FoundationBase.h"
5#include "../Platform/Atomic.h"
7#include <OsoMemoryProfiler/CogsMemoryProfile.h>
16 constexpr size_t kDefaultAlignment = 8;
19#if defined(_M_X64) || defined(__amd64__)
20 constexpr size_t kDefaultAlignment = 16;
22 constexpr size_t kDefaultAlignment = 8;
50 virtual void * allocate(
size_t size,
size_t alignment = 0, MemBlockType type = MemBlockType::Block);
60 virtual void deallocate(
void * ptr,
size_t size, MemBlockType type = MemBlockType::Block);
62 virtual void changeType(
void* ptr,
size_t size, MemBlockType oldType, MemBlockType newType);
71 Cogs::Atomic<size_t> allocated{0};
72 Cogs::Atomic<size_t> allocations{0};
83 T * create(Allocator * allocator)
85 void * memory = allocator->allocate(
sizeof(T),
alignof(T));
87 return new (memory) T();
100 template<
typename T,
typename... Args>
101 T * create(Allocator * allocator, Args&&... args)
103 void * memory = allocator->allocate(
sizeof(T),
alignof(T));
105 return new (memory) T(std::forward<Args>(args)...);
117 void destroy(T * t, Allocator * allocator)
121 allocator->deallocate(t,
sizeof(T));
Base allocator implementation.
virtual size_t getAllocatedBytes() const
Return the number of bytes currently allocated by this allocator.
virtual size_t getAllocationCount() const
Return the number of allocations currently allocated by this allocator.
Contains all Cogs related functionality.