3#include "../Logging/Logger.h"
5#if defined(_WIN32) && defined(COGS_FOUNDATION_ALIGNED_MALLOC)
6#define USE_ALIGNED_MALLOC
26 return defaultAllocator();
34#ifdef USE_ALIGNED_MALLOC
35 void * memory = _aligned_malloc(size, alignment > kDefaultAlignment ? alignment : kDefaultAlignment);
37 void * memory =
nullptr;
38 if (alignment <= kDefaultAlignment) {
39 memory = malloc(size);
41 assert(
false &&
"Unsupported alignment restrictions.");
46 LOG_ERROR(logger,
"Failed to allocate %zd bytes of %zd byte aligned memory.", size, alignment);
49 OsoMP_Allocate(uint8_t(type), memory, size,
nullptr, 0);
53 assert((intptr_t)memory % kDefaultAlignment == 0 &&
"Invalid base alignment");
61 OsoMP_Free(uint8_t(type), ptr,
nullptr, 0);
63#ifdef USE_ALIGNED_MALLOC
72void Cogs::Memory::Allocator::changeType(
void* ptr,
size_t size, MemBlockType oldType, MemBlockType newType)
78 OsoMP_Free(uint8_t(oldType), ptr,
nullptr, 0);
79 OsoMP_Allocate(uint8_t(newType), ptr, size,
nullptr, 0);
Log implementation class.
Base allocator implementation.
static Allocator * defaultAllocator()
Gets the system default allocator.
virtual void deallocate(void *ptr, size_t size, MemBlockType type=MemBlockType::Block)
Deallocate the memory block at the given pointer, with the given size.
virtual void * allocate(size_t size, size_t alignment=0, MemBlockType type=MemBlockType::Block)
Allocate raw memory.
static Allocator * overflowAllocator()
constexpr Log getLogger(const char(&name)[LEN]) noexcept