xo-interpreter2 .. xo-arena. memory pool introspection
This commit is contained in:
parent
c89e28367c
commit
11293d254e
9 changed files with 38 additions and 53 deletions
|
|
@ -19,13 +19,13 @@ namespace xo {
|
|||
struct ArenaConfig {
|
||||
/** @defgroup mm-arenaconfig-ctors **/
|
||||
|
||||
ArenaConfig with_name(std::string name) {
|
||||
ArenaConfig with_name(std::string name) const {
|
||||
ArenaConfig copy(*this);
|
||||
copy.name_ = name;
|
||||
return copy;
|
||||
}
|
||||
|
||||
ArenaConfig with_size(std::size_t z) {
|
||||
ArenaConfig with_size(std::size_t z) const {
|
||||
ArenaConfig copy(*this);
|
||||
copy.size_ = z;
|
||||
return copy;
|
||||
|
|
|
|||
|
|
@ -138,12 +138,14 @@ namespace xo {
|
|||
**/
|
||||
AllocHeader * end_header() const noexcept;
|
||||
|
||||
/** report memory use for this arena to @p fn.
|
||||
* For DArena reporting just one pool = arena's memory range
|
||||
**/
|
||||
void visit_pools(const MemorySizeVisitor & fn) const;
|
||||
|
||||
/** get header from allocated object address **/
|
||||
header_type * obj2hdr(void * obj) noexcept;
|
||||
|
||||
/** resource ocnsumption in normal form **/
|
||||
MemorySizeInfo _store_info() const noexcept;
|
||||
|
||||
/** report alloc book-keeping info for allocation at @p mem
|
||||
*
|
||||
* Require:
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace xo {
|
|||
using value_type = std::pair<const Key, Value>;
|
||||
using key_hash = Hash;
|
||||
using key_equal = Equal;
|
||||
using MemorySizeInfo = xo::mm::MemorySizeInfo;
|
||||
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
|
||||
using byte = std::byte;
|
||||
using group_type = detail::ControlGroup;
|
||||
using store_type = detail::HashMapStore<Key, Value>;
|
||||
|
|
@ -77,9 +77,8 @@ namespace xo {
|
|||
iterator begin() { return _promote_iterator(_begin_aux()); }
|
||||
iterator end() { return _promote_iterator(_end_aux()); }
|
||||
|
||||
std::size_t _n_store() const noexcept { return store_._n_store(); }
|
||||
MemorySizeInfo _store_info(std::size_t i) const noexcept {
|
||||
return store_._store_info(i);
|
||||
void visit_pools(const MemorySizeVisitor & visitor) const {
|
||||
return store_.visit_pools(visitor);
|
||||
}
|
||||
|
||||
/** insert @p kv_pair into hash map.
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ namespace xo {
|
|||
/** arena used for element storage
|
||||
* (Might prefer obj<AResourceVisitor> here; refrain to avoid leveling violation)
|
||||
**/
|
||||
MemorySizeInfo _store_info() const { return store_._store_info(); }
|
||||
void visit_pools(const MemorySizeVisitor & fn) const { store_.visit_pools(fn); }
|
||||
|
||||
/** reserve space, if possible, for at least @p z elements.
|
||||
* Always limited by ArenaConfig.size_
|
||||
|
|
|
|||
|
|
@ -83,8 +83,8 @@ namespace xo {
|
|||
const_span_type occupied_range() const noexcept { return occupied_range_; }
|
||||
const_span_type input_range() const noexcept { return input_range_; }
|
||||
|
||||
std::size_t _n_store() const noexcept;
|
||||
MemorySizeInfo _store_info(std::size_t i) const noexcept;
|
||||
/** report memory-size info for this buffer to @p fn **/
|
||||
void visit_pools(const MemorySizeVisitor & fn) const;
|
||||
|
||||
/** verify DCircularBuffer invariants.
|
||||
* Act on failure according to policy @p p
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
#include <cstddef>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
|
@ -31,7 +32,12 @@ namespace xo {
|
|||
std::size_t reserved_ = 0;
|
||||
};
|
||||
|
||||
}
|
||||
/** function that visits MemorySizeInfo for a collection of @p n memory pools.
|
||||
* Each pool reported with index @p i in [0, n), with associated
|
||||
* size record @p info.
|
||||
**/
|
||||
using MemorySizeVisitor = std::function<void (const MemorySizeInfo & info)>;
|
||||
}
|
||||
}
|
||||
|
||||
/* end MemorySizeInfo.hpp */
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace xo {
|
|||
using group_type = detail::ControlGroup;
|
||||
using control_vector_type = xo::mm::DArenaVector<uint8_t>;
|
||||
using slot_vector_type = xo::mm::DArenaVector<value_type>;
|
||||
using MemorySizeInfo = xo::mm::MemorySizeInfo;
|
||||
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
|
||||
|
||||
public:
|
||||
/** group_exp2: number of groups {x, 2^x} **/
|
||||
|
|
@ -48,16 +48,9 @@ namespace xo {
|
|||
size_type capacity() const noexcept { return n_group_ * c_group_size; }
|
||||
float load_factor() const noexcept { return size_ / static_cast<float>(n_slot_); }
|
||||
|
||||
std::size_t _n_store() const noexcept { return 2; }
|
||||
MemorySizeInfo _store_info(std::size_t i) const noexcept {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return control_._store_info();
|
||||
case 1:
|
||||
return slots_._store_info();
|
||||
}
|
||||
|
||||
return MemorySizeInfo::sentinel();
|
||||
void visit_pools(const MemorySizeVisitor & visitor) const {
|
||||
control_.visit_pools(visitor);
|
||||
slots_.visit_pools(visitor);
|
||||
}
|
||||
|
||||
void resize_from_empty(const std::pair<size_type,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue