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
|
// Reset the arena, potentially also releasing committed pages
|
||||||
void reset();
|
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:
|
private:
|
||||||
Region m_region;
|
Region m_region;
|
||||||
size_t m_minSize;
|
size_t m_minSize;
|
||||||
|
|||||||
@@ -60,6 +60,20 @@ bool Arena::init(size_t minSize, size_t maxSize)
|
|||||||
return m_region.init(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)
|
std::byte* Arena::alloc(size_t size)
|
||||||
{
|
{
|
||||||
size_t neededSize = m_usedSize + size;
|
size_t neededSize = m_usedSize + size;
|
||||||
@@ -70,7 +84,9 @@ std::byte* Arena::alloc(size_t size)
|
|||||||
if (newSize < m_minSize) {
|
if (newSize < m_minSize) {
|
||||||
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;
|
std::byte* ret = m_region.getAddress() + m_usedSize;
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ bool Region::resize(size_t size)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newSize > m_maxSize) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (newSize > m_committedSize) {
|
if (newSize > m_committedSize) {
|
||||||
// ---- Growing ----
|
// ---- Growing ----
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ enable_testing()
|
|||||||
add_executable(
|
add_executable(
|
||||||
mimir_test
|
mimir_test
|
||||||
"region_test.cpp"
|
"region_test.cpp"
|
||||||
)
|
"arena_test.cpp"
|
||||||
|
"test_util.cpp")
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
mimir_test
|
mimir_test
|
||||||
GTest::gtest_main
|
GTest::gtest_main
|
||||||
|
|||||||
@@ -1,25 +1,10 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "mimir.h"
|
#include "mimir.h"
|
||||||
|
|
||||||
|
#include "test_util.h"
|
||||||
|
|
||||||
namespace mimir_tests {
|
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)
|
TEST(Region, InitialState)
|
||||||
{
|
{
|
||||||
mimir::init();
|
mimir::init();
|
||||||
|
|||||||
Reference in New Issue
Block a user