Add Arena::getMaxSize() and Arena::getUsed(). Make Arena tests discoverable.
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
This commit is contained in:
@@ -56,6 +56,14 @@ public:
|
||||
|
||||
// Reset the arena, potentially also releasing committed pages
|
||||
void reset();
|
||||
|
||||
// Get the actual used size.
|
||||
// This may differ from the sum of allocations due to alignment requirements.
|
||||
size_t getUsed() const;
|
||||
|
||||
// Get the actual maximum size.
|
||||
// This may be greater than the maxSize passed into init, due to page size alignment.
|
||||
size_t getMaxSize() const;
|
||||
private:
|
||||
Region m_region;
|
||||
size_t m_minSize;
|
||||
|
||||
@@ -60,6 +60,20 @@ bool Arena::init(size_t minSize, size_t maxSize)
|
||||
return m_region.init(maxSize);
|
||||
}
|
||||
|
||||
// Get the actual used size.
|
||||
// This may differ from the sum of allocations due to alignment requirements.
|
||||
size_t Arena::getUsed() const
|
||||
{
|
||||
return m_usedSize;
|
||||
}
|
||||
|
||||
// Get the actual maximum size.
|
||||
// This may be greater than the maxSize passed into init, due to page size alignment.
|
||||
size_t Arena::getMaxSize() const
|
||||
{
|
||||
return m_region.getSize();
|
||||
}
|
||||
|
||||
std::byte* Arena::alloc(size_t size)
|
||||
{
|
||||
size_t neededSize = m_usedSize + size;
|
||||
@@ -70,7 +84,9 @@ std::byte* Arena::alloc(size_t size)
|
||||
if (newSize < m_minSize) {
|
||||
newSize = m_minSize;
|
||||
}
|
||||
m_region.resize(newSize);
|
||||
if (!m_region.resize(newSize)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::byte* ret = m_region.getAddress() + m_usedSize;
|
||||
|
||||
@@ -93,6 +93,10 @@ bool Region::resize(size_t size)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (newSize > m_maxSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newSize > m_committedSize) {
|
||||
// ---- Growing ----
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
@@ -15,7 +15,8 @@ enable_testing()
|
||||
add_executable(
|
||||
mimir_test
|
||||
"region_test.cpp"
|
||||
)
|
||||
"arena_test.cpp"
|
||||
"test_util.cpp")
|
||||
target_link_libraries(
|
||||
mimir_test
|
||||
GTest::gtest_main
|
||||
|
||||
@@ -1,25 +1,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "mimir.h"
|
||||
|
||||
#include "test_util.h"
|
||||
|
||||
namespace mimir_tests {
|
||||
|
||||
void writeData(std::byte* dest, size_t count, int seed)
|
||||
{
|
||||
for (int i = 0; i < count; i++) {
|
||||
dest[i] = std::byte((seed * 3162 + i * 63163) % 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkData(std::byte* src, size_t count, int seed)
|
||||
{
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (src[i] != std::byte((seed * 3162 + i * 63163) % 0xff)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(Region, InitialState)
|
||||
{
|
||||
mimir::init();
|
||||
|
||||
Reference in New Issue
Block a user