From: "Mauricio Fernández" Date: 2003-05-19T01:28:16+09:00 Subject: Re: ruby garbage collection On Sun, May 18, 2003 at 11:30:48PM +0900, Simon Strandgaard wrote: > On Mon, 19 May 2003 00:15:33 +0900, Gaffer wrote: > > > an interesting aside, is there any benefit to using ruby's ALLOC etc. > > functions over new/delete? i notice you dont, cheers > > I don't know the difference: new/delete versus rubys ALLOC. > Can anyone shed some light on this ? If you go through Ruby's allocation (ALLOC is equivalent to xmalloc which is normally ruby_xmalloc) the information on how much memory has been allocated is updated. If more than malloc_limit (a changing threshold) bytes have been allocated a GC run is performed. This means Ruby will not GC if you use new or malloc directly, but it might start GC()ing in the middle of ALLOC. You should bypass Ruby's ALLOC if you're pretty confident that no memory will be regained in the GC pass. void * ruby_xmalloc(size) long size; { void *mem; if (size < 0) { rb_raise(rb_eNoMemError, "negative allocation size (or too big)"); } if (size == 0) size = 1; malloc_increase += size; if (malloc_increase > malloc_limit) { rb_gc(); } RUBY_CRITICAL(mem = malloc(size)); if (!mem) { rb_gc(); RUBY_CRITICAL(mem = malloc(size)); if (!mem) { rb_memerror(); } } return mem; } -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Linux: Where Don't We Want To Go Today? -- Submitted by Pancrazio De Mauro, paraphrasing some well-known sales talk