Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 17018) +++ include/ruby/intern.h (working copy) @@ -340,6 +340,8 @@ VALUE rb_gc_enable(void); VALUE rb_gc_disable(void); VALUE rb_gc_start(void); +size_t rb_gc_malloc_allocated_size(void); +size_t rb_gc_malloc_allocations(void); /* hash.c */ void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t); void rb_hash_foreach(VALUE, int (*)(ANYARGS), VALUE); Index: configure.in =================================================================== --- configure.in (revision 17018) +++ configure.in (working copy) @@ -1905,6 +1905,14 @@ fi AC_SUBST(MANTYPE) +AC_ARG_ENABLE(gc-malloc-stats, + [ --enable-gc-malloc-stats enable GC.malloc_allocations and GC.malloc_allocated_size.], + [gc_malloc_stats=$enableval], [gc_malloc_stats=no]) +if test $gc_malloc_stats = yes; then + AC_DEFINE(CALC_EXACT_MALLOC_SIZE) +fi + + arch_hdrdir="${EXTOUT}/include/${arch}/ruby" $MAKEDIRS "${arch_hdrdir}" config_h="${arch_hdrdir}/config.h" Index: gc.c =================================================================== --- gc.c (revision 17018) +++ gc.c (working copy) @@ -143,7 +143,9 @@ struct gc_list *next; }; +#ifndef CALC_EXACT_MALLOC_SIZE #define CALC_EXACT_MALLOC_SIZE 0 +#endif typedef struct rb_objspace { struct { @@ -2414,9 +2416,15 @@ static VALUE gc_malloc_allocated_size(VALUE self) { - return UINT2NUM((&rb_objspace)->malloc_params.allocated_size); + return UINT2NUM(rb_gc_malloc_allocated_size()); } +size_t +rb_gc_malloc_allocated_size(void) +{ + return (&rb_objspace)->malloc_params.allocated_size; +} + /* * call-seq: * GC.malloc_allocations -> Integer @@ -2429,8 +2437,14 @@ static VALUE gc_malloc_allocations(VALUE self) { - return UINT2NUM((&rb_objspace)->malloc_params.allocations); + return UINT2NUM(rb_gc_malloc_allocations()); } + +size_t +rb_gc_malloc_allocations(void) +{ + return (&rb_objspace)->malloc_params.allocations; +} #endif /*