diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/extension.rdoc | 12 | ||||
-rw-r--r-- | gc.c | 12 | ||||
-rw-r--r-- | include/ruby/intern.h | 1 |
4 files changed, 30 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Tue Sep 20 16:52:23 2016 Nobuyoshi Nakada <[email protected]> + + * gc.c (rb_gc_adjust_memory_usage): notify memory usage to the GC + engine by extension libraries, to trigger GC. [Feature #12690] + Mon Sep 19 17:05:22 2016 Nobuyoshi Nakada <[email protected]> * numeric.c (Init_Numeric), bignum.c (Init_Bignum): deprecate diff --git a/doc/extension.rdoc b/doc/extension.rdoc index 7eb173debe..b8fbb787ba 100644 --- a/doc/extension.rdoc +++ b/doc/extension.rdoc @@ -1652,6 +1652,18 @@ int rb_remove_event_hook(rb_event_hook_func_t func) :: Removes the specified hook function. +== Memory usage + +void rb_gc_adjust_memory_usage(ssize_t diff) :: + + Adjusts the amount of registered external memory. You can tell GC how + much memory is used by an external library by this function. Calling + this function with positive diff means the memory usage is increased; + new memory block is allocated or a block is reallocated as larger + size. Calling this function with negative diff means the memory usage + is decreased; a memory block is freed or a block is reallocated as + smaller size. This function may trigger the GC. + == Macros for Compatibility Some macros to check API compatibilities are available by default. @@ -8096,6 +8096,18 @@ gc_malloc_allocations(VALUE self) } #endif +void +rb_gc_adjust_memory_usage(ssize_t diff) +{ + rb_objspace_t *objspace = &rb_objspace; + if (diff > 0) { + objspace_malloc_increase(objspace, 0, diff, 0, MEMOP_TYPE_REALLOC); + } + else if (diff < 0) { + objspace_malloc_increase(objspace, 0, 0, -diff, MEMOP_TYPE_REALLOC); + } +} + /* ------------------------------ WeakMap ------------------------------ */ diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 48608f32c3..efa8f4058c 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -502,6 +502,7 @@ VALUE rb_undefine_finalizer(VALUE); size_t rb_gc_count(void); size_t rb_gc_stat(VALUE); VALUE rb_gc_latest_gc_info(VALUE); +void rb_gc_adjust_memory_usage(ssize_t); /* hash.c */ void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t); VALUE rb_check_hash_type(VALUE); |