diff --git a/shared/source/utilities/heap_allocator.h b/shared/source/utilities/heap_allocator.h index ee2fae6345..669dd6321d 100644 --- a/shared/source/utilities/heap_allocator.h +++ b/shared/source/utilities/heap_allocator.h @@ -31,7 +31,7 @@ class HeapAllocator { HeapAllocator(uint64_t address, uint64_t size, size_t allocationAlignment) : HeapAllocator(address, size, allocationAlignment, 4 * MemoryConstants::megaByte) { } - HeapAllocator(uint64_t address, uint64_t size, size_t allocationAlignment, size_t threshold) : baseAddress(address), size(size), availableSize(size), allocationAlignment(allocationAlignment), sizeThreshold(threshold) { + HeapAllocator(uint64_t address, uint64_t size, size_t allocationAlignment, size_t threshold) : size(size), availableSize(size), allocationAlignment(allocationAlignment), sizeThreshold(threshold) { pLeftBound = address; pRightBound = address + size; freedChunksBig.reserve(10); @@ -59,11 +59,10 @@ class HeapAllocator { double getUsage() const; uint64_t getBaseAddress() const { - return this->baseAddress; + return this->pLeftBound; } protected: - const uint64_t baseAddress; const uint64_t size; uint64_t availableSize; uint64_t pLeftBound; diff --git a/shared/test/unit_test/utilities/heap_allocator_tests.cpp b/shared/test/unit_test/utilities/heap_allocator_tests.cpp index ae572a6472..eae44d2d5f 100644 --- a/shared/test/unit_test/utilities/heap_allocator_tests.cpp +++ b/shared/test/unit_test/utilities/heap_allocator_tests.cpp @@ -1438,19 +1438,14 @@ TEST(HeapAllocatorTest, givenZeroAlignmentPassedWhenAllocatingMemoryWithCustomAl EXPECT_EQ(alignUp(heapBase, allocationAlignment), ptr); } -TEST(HeapAllocatorTest, whenGetBaseAddressIsCalledThenReturnInitialBaseAddress) { +TEST(HeapAllocatorTest, whenGetBaseAddressIsCalledThenReturnInitialLeftBoundAddress) { const uint64_t heapBase = 0x100000llu; - const size_t heapSize = 16 * MemoryConstants::megaByte; - const size_t sizeThreshold = 4 * MemoryConstants::megaByte; - + const size_t heapSize = 1024 * 4096; HeapAllocatorUnderTest heapAllocator(heapBase, heapSize, allocationAlignment, sizeThreshold); + EXPECT_EQ(heapBase, heapAllocator.getBaseAddress()); - size_t bigChunk = 5 * MemoryConstants::megaByte; - EXPECT_NE(0u, heapAllocator.allocate(bigChunk)); - EXPECT_EQ(heapBase, heapAllocator.getBaseAddress()); - - size_t smallChunk = 4096; - EXPECT_NE(0u, heapAllocator.allocate(smallChunk)); + size_t sizeToAlloc = 4096; + heapAllocator.allocate(sizeToAlloc); EXPECT_EQ(heapBase, heapAllocator.getBaseAddress()); } \ No newline at end of file