From f12ce7874fd9ae669967b5c3788698302535f60d Mon Sep 17 00:00:00 2001 From: Emiel Por Date: Wed, 11 Dec 2024 14:25:57 -0800 Subject: [PATCH] Copy using std::copy(). --- benchmarks/pool_allocator.cpp | 2 +- catkit_core/FreeListAllocator.cpp | 4 +++- catkit_core/PoolAllocator.cpp | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/benchmarks/pool_allocator.cpp b/benchmarks/pool_allocator.cpp index 9c642e1c..f327cf4e 100644 --- a/benchmarks/pool_allocator.cpp +++ b/benchmarks/pool_allocator.cpp @@ -12,7 +12,7 @@ void benchmark_linux_scalability() PoolAllocator allocator(buffer); allocator.Initialize(CAPACITY); - auto *handles = new size_t[N]; + auto *handles = new PoolAllocator::BlockHandle[N]; auto start = GetTimeStamp(); diff --git a/catkit_core/FreeListAllocator.cpp b/catkit_core/FreeListAllocator.cpp index df1ff108..08ed799b 100644 --- a/catkit_core/FreeListAllocator.cpp +++ b/catkit_core/FreeListAllocator.cpp @@ -1,6 +1,8 @@ #include "FreeListAllocator.h" #include "Timing.h" + #include +#include //#define DEBUG_PRINT(a) std::cout << a << std::endl #define DEBUG_PRINT(a) @@ -76,7 +78,7 @@ std::size_t FreeListAllocator::ComputeMetadataBufferSize(std::size_t max_num_blo void FreeListAllocator::Initialize(std::size_t max_num_blocks, std::size_t alignment, std::size_t buffer_size) { - std::memcpy(m_Header.version, VERSION, sizeof(VERSION)); + std::copy(VERSION, VERSION + sizeof(VERSION), m_Header.version); m_Header.max_num_blocks = max_num_blocks; m_Header.alignment = alignment; m_Header.total_buffer_size = buffer_size; diff --git a/catkit_core/PoolAllocator.cpp b/catkit_core/PoolAllocator.cpp index a7c38f55..6882986d 100644 --- a/catkit_core/PoolAllocator.cpp +++ b/catkit_core/PoolAllocator.cpp @@ -1,5 +1,7 @@ #include "PoolAllocator.h" +#include + const std::uint8_t VERSION[4] = {0, 0, 0, 0}; PoolAllocator::PoolAllocator(void *metadata_buffer) @@ -13,7 +15,7 @@ PoolAllocator::PoolAllocator(void *metadata_buffer) void PoolAllocator::Initialize(std::uint32_t capacity) { // Set version and capacity. - std::memcpy(m_Header.version, VERSION, sizeof(VERSION)); + std::copy(VERSION, VERSION + sizeof(VERSION), m_Header.version); m_Capacity = capacity; // Initialize the linked list.