xo-interpreter2 stack: + MemorySizeInfo.used + pop for DArenaHashMap
This commit is contained in:
parent
f9e266b0fc
commit
1c29400495
4 changed files with 28 additions and 6 deletions
|
|
@ -15,15 +15,18 @@ namespace xo {
|
||||||
struct MemorySizeInfo {
|
struct MemorySizeInfo {
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
|
|
||||||
MemorySizeInfo(std::string_view name, std::size_t a, std::size_t c, std::size_t r)
|
MemorySizeInfo() = default;
|
||||||
: resource_name_{name}, allocated_{a}, committed_{c}, reserved_{r}
|
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 **/
|
/** resource name **/
|
||||||
std::string_view 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;
|
std::size_t allocated_ = 0;
|
||||||
/** memory committed (backed by physical memory) **/
|
/** memory committed (backed by physical memory) **/
|
||||||
std::size_t committed_ = 0;
|
std::size_t committed_ = 0;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ namespace xo {
|
||||||
using control_vector_type = xo::mm::DArenaVector<uint8_t>;
|
using control_vector_type = xo::mm::DArenaVector<uint8_t>;
|
||||||
using slot_vector_type = xo::mm::DArenaVector<value_type>;
|
using slot_vector_type = xo::mm::DArenaVector<value_type>;
|
||||||
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
|
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
|
||||||
|
using MemorySizeInfo = xo::mm::MemorySizeInfo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** group_exp2: number of groups {x, 2^x} **/
|
/** group_exp2: number of groups {x, 2^x} **/
|
||||||
|
|
@ -51,8 +52,20 @@ namespace xo {
|
||||||
float load_factor() const noexcept { return size_ / static_cast<float>(n_slot_); }
|
float load_factor() const noexcept { return size_ / static_cast<float>(n_slot_); }
|
||||||
|
|
||||||
void visit_pools(const MemorySizeVisitor & visitor) const {
|
void visit_pools(const MemorySizeVisitor & visitor) const {
|
||||||
control_.visit_pools(visitor);
|
// complexity here in service of HashMapStore-specific value for MemorySizeInfo.used
|
||||||
slots_.visit_pools(visitor);
|
|
||||||
|
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::pair<size_type,
|
void resize_from_empty(const std::pair<size_type,
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,12 @@ namespace xo {
|
||||||
|
|
||||||
void
|
void
|
||||||
DArena::visit_pools(const MemorySizeVisitor & fn) const {
|
DArena::visit_pools(const MemorySizeVisitor & fn) const {
|
||||||
|
/** arena can't tell purpose of allocated memory;
|
||||||
|
* must assume it's all used
|
||||||
|
**/
|
||||||
|
|
||||||
fn(MemorySizeInfo(config_.name_,
|
fn(MemorySizeInfo(config_.name_,
|
||||||
|
this->allocated() /*used*/,
|
||||||
this->allocated(),
|
this->allocated(),
|
||||||
this->committed(),
|
this->committed(),
|
||||||
this->reserved()));
|
this->reserved()));
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ namespace xo {
|
||||||
DCircularBuffer::visit_pools(const MemorySizeVisitor & visitor) const
|
DCircularBuffer::visit_pools(const MemorySizeVisitor & visitor) const
|
||||||
{
|
{
|
||||||
visitor(MemorySizeInfo(config_.name_,
|
visitor(MemorySizeInfo(config_.name_,
|
||||||
|
occupied_range_.size() /*used*/,
|
||||||
occupied_range_.size(),
|
occupied_range_.size(),
|
||||||
mapped_range_.size(),
|
mapped_range_.size(),
|
||||||
reserved_range_.size()));
|
reserved_range_.size()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue