Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/decodeless/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class linear_memory_resource {
linear_memory_resource(size_t initialSize, ResOrAlloc&& parent)
requires memory_resource<ResOrAlloc>
: m_parent(std::move(parent))
, m_begin(allocate_bytes(m_parent, initialSize))
, m_begin(initialSize != 0 ? allocate_bytes(m_parent, initialSize) : nullptr)
, m_next(reinterpret_cast<uintptr_t>(m_begin))
, m_end(reinterpret_cast<uintptr_t>(m_begin) + initialSize) {
if constexpr (nonrealloc_memory_resource<ResOrAlloc>) {
Expand Down
20 changes: 19 additions & 1 deletion test/src/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,30 @@ TEST_F(Allocate, EmptyNonrealloc) {
EXPECT_EQ(memory.capacity(), 42);
}

TEST_F(Allocate, EmptyRealloc) {
TEST_F(Allocate, EmptyReallocDefault) {
linear_memory_resource<ReallocNullAllocator> memory;
EXPECT_EQ(memory.size(), 0);
EXPECT_EQ(memory.capacity(), 0);
}

TEST_F(Allocate, EmptyRealloc) {
linear_memory_resource<ReallocNullMemoryResource> memory{ReallocNullMemoryResource()};
EXPECT_EQ(memory.size(), 0);
EXPECT_EQ(memory.capacity(), 0);
}

TEST_F(Allocate, ZeroInitialRealloc) {
linear_memory_resource<ReallocNullAllocator> memory{0, ReallocNullAllocator()};
EXPECT_EQ(memory.size(), 0);
EXPECT_EQ(memory.capacity(), 0);
}

TEST_F(Allocate, ZeroInitialReallocMemoryResource) {
linear_memory_resource<ReallocNullMemoryResource> memory{0, ReallocNullMemoryResource()};
EXPECT_EQ(memory.size(), 0);
EXPECT_EQ(memory.capacity(), 0);
}

TEST_F(Allocate, Truncate) {
linear_memory_resource<ReallocNullAllocator> memory;
std::ignore = memory.allocate(1, 1);
Expand Down