Skip to content

Commit

Permalink
Copy using std::copy().
Browse files Browse the repository at this point in the history
  • Loading branch information
ehpor committed Dec 11, 2024
1 parent 1f31a26 commit f12ce78
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion benchmarks/pool_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 3 additions & 1 deletion catkit_core/FreeListAllocator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "FreeListAllocator.h"
#include "Timing.h"

#include <iostream>
#include <algorithm>

//#define DEBUG_PRINT(a) std::cout << a << std::endl
#define DEBUG_PRINT(a)
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion catkit_core/PoolAllocator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "PoolAllocator.h"

#include <algorithm>

const std::uint8_t VERSION[4] = {0, 0, 0, 0};

PoolAllocator::PoolAllocator(void *metadata_buffer)
Expand All @@ -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.
Expand Down

0 comments on commit f12ce78

Please sign in to comment.