diff --git a/Source/Engine/Core/Memory/Memory.h b/Source/Engine/Core/Memory/Memory.h index 770fd2c22..a35929ed2 100644 --- a/Source/Engine/Core/Memory/Memory.h +++ b/Source/Engine/Core/Memory/Memory.h @@ -36,6 +36,32 @@ namespace AllocatorExt return result; } + /// + /// Reallocates block of the memory. + /// + /// + /// A pointer to the memory block to reallocate. + /// The size of the new allocation (in bytes). + /// The memory alignment (in bytes). Must be an integer power of 2. + /// The pointer to the allocated chunk of the memory. The pointer is a multiple of alignment. + inline void* ReallocWithAlignment(void* ptr, uint64 newSize, uint64 alignment) + { + if (newSize == 0) + { + Allocator::Free(ptr); + return nullptr; + } + if (!ptr) + return Allocator::Allocate(newSize, alignment); + void* result = Allocator::Allocate(newSize, alignment); + if (result) + { + Platform::MemoryCopy(result, ptr, newSize); + Allocator::Free(ptr); + } + return result; + } + /// /// Reallocates block of the memory. ///