diff --git a/include/xo/arena/MemorySizeInfo.hpp b/include/xo/arena/MemorySizeInfo.hpp index 540453f..764eae6 100644 --- a/include/xo/arena/MemorySizeInfo.hpp +++ b/include/xo/arena/MemorySizeInfo.hpp @@ -15,15 +15,18 @@ namespace xo { struct MemorySizeInfo { using size_type = std::size_t; - MemorySizeInfo(std::string_view name, std::size_t a, std::size_t c, std::size_t r) - : resource_name_{name}, allocated_{a}, committed_{c}, reserved_{r} + MemorySizeInfo() = default; + MemorySizeInfo(std::string_view name, std::size_t u, std::size_t a, std::size_t c, std::size_t r) + : resource_name_{name}, used_{u}, allocated_{a}, committed_{c}, reserved_{r} {} - static MemorySizeInfo sentinel() { return MemorySizeInfo("", 0, 0, 0); } + static MemorySizeInfo sentinel() { return MemorySizeInfo(); } /** resource name **/ std::string_view resource_name_; - /** memory in-use **/ + /** memory used (excluding wasted space) **/ + std::size_t used_ = 0; + /** memory allocated (including wasted space e.g. empty slots in hash tables **/ std::size_t allocated_ = 0; /** memory committed (backed by physical memory) **/ std::size_t committed_ = 0; diff --git a/include/xo/arena/hashmap/HashMapStore.hpp b/include/xo/arena/hashmap/HashMapStore.hpp index 436e88e..6393bb0 100644 --- a/include/xo/arena/hashmap/HashMapStore.hpp +++ b/include/xo/arena/hashmap/HashMapStore.hpp @@ -20,6 +20,7 @@ namespace xo { using control_vector_type = xo::mm::DArenaVector; using slot_vector_type = xo::mm::DArenaVector; using MemorySizeVisitor = xo::mm::MemorySizeVisitor; + using MemorySizeInfo = xo::mm::MemorySizeInfo; public: /** group_exp2: number of groups {x, 2^x} **/ @@ -51,8 +52,20 @@ namespace xo { float load_factor() const noexcept { return size_ / static_cast(n_slot_); } void visit_pools(const MemorySizeVisitor & visitor) const { - control_.visit_pools(visitor); - slots_.visit_pools(visitor); + // complexity here in service of HashMapStore-specific value for MemorySizeInfo.used + + MemorySizeInfo ctl_info; + MemorySizeInfo slot_info; + + control_.visit_pools([&ctl_info](const auto & x) { ctl_info = x; }); + slots_.visit_pools([&slot_info](const auto & x) { slot_info = x; }); + + // control: 1 byte per (key,value) pair + ctl_info.used_ = size_; + slot_info.used_ = size_ * sizeof(value_type); + + visitor(ctl_info); + visitor(slot_info); } void resize_from_empty(const std::pairallocated() /*used*/, this->allocated(), this->committed(), this->reserved())); diff --git a/src/arena/DCircularBuffer.cpp b/src/arena/DCircularBuffer.cpp index 372462f..e5b1c72 100644 --- a/src/arena/DCircularBuffer.cpp +++ b/src/arena/DCircularBuffer.cpp @@ -83,6 +83,7 @@ namespace xo { DCircularBuffer::visit_pools(const MemorySizeVisitor & visitor) const { visitor(MemorySizeInfo(config_.name_, + occupied_range_.size() /*used*/, occupied_range_.size(), mapped_range_.size(), reserved_range_.size()));