/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Foundation/Memory/Policies/AllocPolicyHeap.h
49 строк
2 KB
C-Core
Re-enabled security relevant warnings (#1339)
25 июн 2024, 12:03
Не верифицирован
25 июн 2024, 12:03
7083663
Код
Авторство
О чём код?
#pragma once #include <Foundation/Basics.h> /// \brief Default heap memory allocation policy. /// /// \see ezAllocatorWithPolicy class ezAllocPolicyHeap { public: EZ_ALWAYS_INLINE ezAllocPolicyHeap(ezAllocator* pParent) { EZ_IGNORE_UNUSED(pParent); } EZ_ALWAYS_INLINE ~ezAllocPolicyHeap() = default; EZ_FORCE_INLINE void* Allocate(size_t uiSize, size_t uiAlign) { EZ_IGNORE_UNUSED(uiAlign); // malloc has no alignment guarantees, even though on many systems it returns 16 byte aligned data // if these asserts fail, you need to check what container made the allocation and change it // to use an aligned allocator, e.g. ezAlignedAllocatorWrapper // unfortunately using EZ_ALIGNMENT_MINIMUM doesn't work, because even on 32 Bit systems we try to do allocations with 8 Byte // alignment interestingly, the code that does that, seems to work fine anyway EZ_ASSERT_DEBUG(uiAlign <= 8, "This allocator does not guarantee alignments larger than 8. Use an aligned allocator to allocate the desired data type."); void* ptr = malloc(uiSize); EZ_CHECK_ALIGNMENT(ptr, uiAlign); return ptr; } EZ_FORCE_INLINE void* Reallocate(void* pCurrentPtr, size_t uiCurrentSize, size_t uiNewSize, size_t uiAlign) { EZ_IGNORE_UNUSED(uiCurrentSize); EZ_IGNORE_UNUSED(uiAlign); void* ptr = realloc(pCurrentPtr, uiNewSize); EZ_CHECK_ALIGNMENT(ptr, uiAlign); return ptr; } EZ_ALWAYS_INLINE void Deallocate(void* pPtr) { free(pPtr); } EZ_ALWAYS_INLINE ezAllocator* GetParent() const { return nullptr; } };