1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-09-20 07:52:25 +00:00
parent c9dd5918f4
commit 68aa1d81cf
4 changed files with 30 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Tue Sep 20 16:52:23 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* numeric.c (Init_Numeric), bignum.c (Init_Bignum): deprecate

View file

@ -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.

12
gc.c
View file

@ -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 ------------------------------
*/

View file

@ -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);