Skip to content

Instantly share code, notes, and snippets.

@icebreaker
Created November 7, 2011 17:41
Show Gist options
  • Select an option

  • Save icebreaker/1345629 to your computer and use it in GitHub Desktop.

Select an option

Save icebreaker/1345629 to your computer and use it in GitHub Desktop.
Ruby's malloc wrapper found in gc.c .
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;
if (ruby_gc_stress || (malloc_increase+size) > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
if (!mem) {
garbage_collect();
RUBY_CRITICAL(mem = malloc(size));
if (!mem) {
rb_memerror();
}
}
malloc_increase += size;
return mem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment