ruby-changes:44117
From: nobu <ko1@a...>
Date: Tue, 20 Sep 2016 16:52:41 +0900 (JST)
Subject: [ruby-changes:44117] nobu:r56189 (trunk): gc.c: rb_gc_adjust_memory_usage
nobu 2016-09-20 16:52:25 +0900 (Tue, 20 Sep 2016) New Revision: 56189 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56189 Log: gc.c: rb_gc_adjust_memory_usage * gc.c (rb_gc_adjust_memory_usage): notify memory usage to the GC engine by extension libraries, to trigger GC. [Feature #12690] Modified files: trunk/ChangeLog trunk/doc/extension.rdoc trunk/gc.c trunk/include/ruby/intern.h Index: doc/extension.rdoc =================================================================== --- doc/extension.rdoc (revision 56188) +++ doc/extension.rdoc (revision 56189) @@ -1652,6 +1652,18 @@ int rb_remove_event_hook(rb_event_hook_f https://github.com/ruby/ruby/blob/trunk/doc/extension.rdoc#L1652 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. Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 56188) +++ include/ruby/intern.h (revision 56189) @@ -502,6 +502,7 @@ VALUE rb_undefine_finalizer(VALUE); https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L502 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); Index: ChangeLog =================================================================== --- ChangeLog (revision 56188) +++ ChangeLog (revision 56189) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Sep 20 16:52:23 2016 Nobuyoshi Nakada <nobu@r...> + + * 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 <nobu@r...> * numeric.c (Init_Numeric), bignum.c (Init_Bignum): deprecate Index: gc.c =================================================================== --- gc.c (revision 56188) +++ gc.c (revision 56189) @@ -8096,6 +8096,18 @@ gc_malloc_allocations(VALUE self) https://github.com/ruby/ruby/blob/trunk/gc.c#L8096 } #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 ------------------------------ */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/