diff --git a/include/xo/arena/DArena.hpp b/include/xo/arena/DArena.hpp index 3ad10db..a325322 100644 --- a/include/xo/arena/DArena.hpp +++ b/include/xo/arena/DArena.hpp @@ -105,6 +105,10 @@ namespace xo { * This is the amount of memory guaranteed to be usable for future allocs from this arena. **/ size_type available() const noexcept { return limit_ - free_; } + /** VM page size for this arena (likely 4KB) **/ + size_type page_z() const noexcept { return page_z_; } + /** Last error encountered by this arena **/ + const AllocError & last_error() const noexcept { return last_error_; } /** True iff address @p addr is owned by this arena, * i.e. falls within [@ref lo_, @ref hi_) diff --git a/include/xo/arena/print.hpp b/include/xo/arena/print.hpp new file mode 100644 index 0000000..5c47476 --- /dev/null +++ b/include/xo/arena/print.hpp @@ -0,0 +1,34 @@ +/** @file print.hpp +* + * @author Roland Conybeare, Dec 2025 + **/ + +#pragma once + +#include "AllocError.hpp" +#include +#include + +namespace xo { + namespace mm { + inline std::ostream & + operator<<(std::ostream & os, const error & x) { + os << AllocError::error_description(x); + return os; + } + + inline std::ostream & + operator<<(std::ostream & os, const AllocError & x) { + os << ""; + return os; + } + } +} + +/* end print.hpp */ diff --git a/utest/DArena.test.cpp b/utest/DArena.test.cpp index 6293c7a..a94b5b0 100644 --- a/utest/DArena.test.cpp +++ b/utest/DArena.test.cpp @@ -3,12 +3,15 @@ * @author Roland Conybeare, Jan 2026 **/ -#include "xo/arena/DArena.hpp" +#include "DArena.hpp" +#include "print.hpp" +#include #include namespace xo { using xo::mm::DArena; using xo::mm::ArenaConfig; + using xo::xtag; using std::byte; namespace ut { @@ -98,6 +101,33 @@ namespace xo { REQUIRE(arena2.committed_z_ == committed_z); } + TEST_CASE("arena-expand-1", "[arena][DArena]") + { + /* typed allocator a1o */ + ArenaConfig cfg { .name_ = "testarena", + .size_ = 1, + .debug_flag_ = false }; + DArena arena = DArena::map(cfg); + + REQUIRE(arena.available() == 0); + REQUIRE(arena.allocated() == 0); + + size_t z2 = 512; + bool ok = arena.expand(z2); + + INFO(xtag("last_error", arena.last_error())); + + REQUIRE(ok); + + REQUIRE(arena.reserved() % arena.page_z() == 0); + REQUIRE(arena.committed() >= z2); + REQUIRE(arena.committed() % arena.page_z() == 0); + REQUIRE(arena.available() >= z2); + REQUIRE(arena.available() == arena.committed()); + REQUIRE(arena.allocated() == 0); + + } + } }