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

This commit is contained in:
2026-09-11 00:08:24 -07:00
parent a7e97b2461
commit 1cb44e96b1
5 changed files with 33 additions and 19 deletions

View File

@@ -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;

View File

@@ -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)