* gc.c (ruby_vm_xmalloc): increase malloc_increase only if malloc

succeeds.  failed malloc size can be huge.  it may increase
  malloc_limit too big which cause less GC and memory full.
  (ruby_vm_xrealloc): ditto.
  (rb_objspace): make params.limit and params.increase size_t.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-05-12 06:28:43 +00:00
Родитель ab24f2b077
Коммит 430cabfad8
2 изменённых файлов: 13 добавлений и 5 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Mon May 12 15:20:02 2008 Tanaka Akira <akr@fsij.org>
* gc.c (ruby_vm_xmalloc): increase malloc_increase only if malloc
succeeds. failed malloc size can be huge. it may increase
malloc_limit too big which cause less GC and memory full.
(ruby_vm_xrealloc): ditto.
(rb_objspace): make params.limit and params.increase size_t.
Mon May 12 15:04:58 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* re.c (rb_reg_prepare_re): made non static with small refactoring.

10
gc.c
Просмотреть файл

@ -145,8 +145,8 @@ struct gc_list {
typedef struct rb_objspace {
struct {
unsigned long limit;
unsigned long increase;
size_t limit;
size_t increase;
} params;
struct {
size_t increment;
@ -314,9 +314,8 @@ ruby_vm_xmalloc(rb_objspace_t *objspace, size_t size)
rb_raise(rb_eNoMemError, "negative allocation size (or too big)");
}
if (size == 0) size = 1;
malloc_increase += size;
if (ruby_gc_stress || malloc_increase > malloc_limit) {
if (ruby_gc_stress || (malloc_increase+size) > malloc_limit) {
garbage_collect(objspace);
}
RUBY_CRITICAL(mem = malloc(size));
@ -328,6 +327,7 @@ ruby_vm_xmalloc(rb_objspace_t *objspace, size_t size)
rb_memerror();
}
}
malloc_increase += size;
return mem;
}
@ -381,7 +381,6 @@ ruby_vm_xrealloc(rb_objspace_t *objspace, void *ptr, size_t size)
}
if (!ptr) return ruby_xmalloc(size);
if (size == 0) size = 1;
malloc_increase += size;
if (ruby_gc_stress) garbage_collect(objspace);
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
@ -392,6 +391,7 @@ ruby_vm_xrealloc(rb_objspace_t *objspace, void *ptr, size_t size)
rb_memerror();
}
}
malloc_increase += size;
return mem;
}