Merge pull request #5032 from RoryO/add-objspace-memsize-of

Add ObjectSpace.memsize_of
This commit is contained in:
Yukihiro "Matz" Matsumoto
2020-07-17 07:10:58 +09:00
committed by GitHub
9 changed files with 427 additions and 0 deletions
+7
View File
@@ -1599,6 +1599,13 @@ mrb_objspace_each_objects(mrb_state *mrb, mrb_each_object_callback *callback, vo
}
}
const mrb_int
mrb_objspace_page_slot_size()
{
const mrb_int i = sizeof(RVALUE);
return i;
}
#ifdef GC_TEST
#ifdef GC_DEBUG
static mrb_value gc_test(mrb_state *, mrb_value);
+14
View File
@@ -518,6 +518,20 @@ ht_foreach(mrb_state *mrb, htable *t, mrb_hash_foreach_func *func, void *p)
}
}
mrb_int
mrb_os_memsize_of_hash_table(mrb_value obj)
{
struct htable *h = mrb_hash_ptr(obj)->ht;
mrb_int segkv_size = 0;
if(h->index) segkv_size = (sizeof(struct segkv) * h->index->capa);
return sizeof(htable) +
sizeof(segindex) +
(sizeof(segment) * h->size) +
segkv_size;
}
/* Iterates over the hash table. */
MRB_API void
mrb_hash_foreach(mrb_state *mrb, struct RHash *hash, mrb_hash_foreach_func *func, void *p)
+9
View File
@@ -4,6 +4,7 @@
** See Copyright Notice in mruby.h
*/
#include <math.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/class.h>
@@ -1128,6 +1129,14 @@ mrb_class_find_path(mrb_state *mrb, struct RClass *c)
return path;
}
mrb_int
mrb_obj_iv_tbl_memsize(mrb_state* mrb, mrb_value obj)
{
return sizeof(iv_tbl) +
(sizeof(segment) * ceil(iv_size(mrb, mrb_obj_ptr(obj)->iv)/
MRB_IV_SEGMENT_SIZE));
}
#define identchar(c) (ISALNUM(c) || (c) == '_' || !ISASCII(c))
mrb_bool