Project

General

Profile

Feature #2837 ยป grow_factor.patch

adgar (Michael Edgar), 03/05/2010 05:20 AM

View differences:

gc.c (working copy)
284 284

  
285 285
#define HEAP_MIN_SLOTS 10000
286 286
#define FREE_MIN  4096
287
#define HEAP_GROW_FACTOR 1.8
287 288

  
289
static float HEAP_GROW_FACTOR_VAL = HEAP_GROW_FACTOR;
290

  
288 291
struct gc_list {
289 292
    VALUE *varptr;
290 293
    struct gc_list *next;
......
977 980
static void
978 981
set_heaps_increment(rb_objspace_t *objspace)
979 982
{
980
    size_t next_heaps_length = (size_t)(heaps_used * 1.8);
983
    size_t next_heaps_length = (size_t)(heaps_used * HEAP_GROW_FACTOR_VAL);
981 984

  
982 985
    if (next_heaps_length == heaps_used) {
983 986
        next_heaps_length++;
......
2981 2984
    return UINT2NUM((&rb_objspace)->count);
2982 2985
}
2983 2986

  
2987
/*
2988
 *  call-seq:
2989
 *     GC.heap_growth_factor -> Float
2990
 *
2991
 *  The rate by which we increase the size of each subsequently allocated heap.
2992
 *
2993
 *  It returns the rate by which we increase the size of each subsequently allocated heap.
2994
 */
2995
 
2996
static VALUE
2997
gc_heap_growth_factor_get(VALUE self)
2998
{
2999
    return rb_float_new(HEAP_GROW_FACTOR_VAL);
3000
}
3001

  
3002
/*
3003
 *
3004
 *  call-seq:
3005
 *     GC.heap_growth_factor = Float   -> Float
3006
 *
3007
 *  Updates the minimum number of slots in each heap slab.
3008
 *
3009
 *  It returns the new number of slots to allocate for each heap slab.
3010
 */
3011
 
3012
static VALUE
3013
gc_heap_growth_factor_set(VALUE self, VALUE new_factor)
3014
{
3015
    HEAP_GROW_FACTOR_VAL = RFLOAT_VALUE(new_factor);
3016
    return new_factor;
3017
}
3018

  
2984 3019
#if CALC_EXACT_MALLOC_SIZE
2985 3020
/*
2986 3021
 *  call-seq:
......
3147 3182
    rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
3148 3183
    rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
3149 3184
    rb_define_singleton_method(rb_mGC, "count", gc_count, 0);
3185
    rb_define_singleton_method(rb_mGC, "heap_growth_factor", gc_heap_growth_factor_get, 0);
3186
    rb_define_singleton_method(rb_mGC, "heap_growth_factor=", gc_heap_growth_factor_set, 1);
3150 3187
    rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
3151 3188

  
3152 3189
    rb_mProfiler = rb_define_module_under(rb_mGC, "Profiler");