Skip to content

Commit 68aa1d8

Browse files
committed
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 ruby#12690] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent c9dd591 commit 68aa1d8

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Tue Sep 20 16:52:23 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* gc.c (rb_gc_adjust_memory_usage): notify memory usage to the GC
4+
engine by extension libraries, to trigger GC. [Feature #12690]
5+
16
Mon Sep 19 17:05:22 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
27

38
* numeric.c (Init_Numeric), bignum.c (Init_Bignum): deprecate

doc/extension.rdoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,18 @@ int rb_remove_event_hook(rb_event_hook_func_t func) ::
16521652

16531653
Removes the specified hook function.
16541654

1655+
== Memory usage
1656+
1657+
void rb_gc_adjust_memory_usage(ssize_t diff) ::
1658+
1659+
Adjusts the amount of registered external memory. You can tell GC how
1660+
much memory is used by an external library by this function. Calling
1661+
this function with positive diff means the memory usage is increased;
1662+
new memory block is allocated or a block is reallocated as larger
1663+
size. Calling this function with negative diff means the memory usage
1664+
is decreased; a memory block is freed or a block is reallocated as
1665+
smaller size. This function may trigger the GC.
1666+
16551667
== Macros for Compatibility
16561668

16571669
Some macros to check API compatibilities are available by default.

gc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8096,6 +8096,18 @@ gc_malloc_allocations(VALUE self)
80968096
}
80978097
#endif
80988098

8099+
void
8100+
rb_gc_adjust_memory_usage(ssize_t diff)
8101+
{
8102+
rb_objspace_t *objspace = &rb_objspace;
8103+
if (diff > 0) {
8104+
objspace_malloc_increase(objspace, 0, diff, 0, MEMOP_TYPE_REALLOC);
8105+
}
8106+
else if (diff < 0) {
8107+
objspace_malloc_increase(objspace, 0, 0, -diff, MEMOP_TYPE_REALLOC);
8108+
}
8109+
}
8110+
80998111
/*
81008112
------------------------------ WeakMap ------------------------------
81018113
*/

include/ruby/intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ VALUE rb_undefine_finalizer(VALUE);
502502
size_t rb_gc_count(void);
503503
size_t rb_gc_stat(VALUE);
504504
VALUE rb_gc_latest_gc_info(VALUE);
505+
void rb_gc_adjust_memory_usage(ssize_t);
505506
/* hash.c */
506507
void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t);
507508
VALUE rb_check_hash_type(VALUE);

0 commit comments

Comments
 (0)