Method: ObjectSpace.memsize_of_all
- Defined in:
- objspace.c
.memsize_of_all([klass]) ⇒ Integer
Return consuming memory size of all living objects.
If klass (should be Class object) is given, return the total memory size of instances of the given class.
Note that the returned size is incomplete. You need to deal with this information as only a HINT. Especially, the size of T_DATA may not be correct.
Note that this method does NOT return total malloc’ed memory size.
This method can be defined by the following Ruby code:
def memsize_of_all klass = false total = 0 ObjectSpace.each_object{|e| total += ObjectSpace.memsize_of(e) if klass == false || e.kind_of?(klass) } total end
This method is only expected to work with C Ruby.
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'objspace.c', line 104
static VALUE
memsize_of_all_m(int argc, VALUE *argv, VALUE self)
{
struct total_data data = {0, 0};
if (argc > 0) {
rb_scan_args(argc, argv, "01", &data.klass);
}
rb_objspace_each_objects(total_i, &data);
return SIZET2NUM(data.total);
}
|