Function rb_sys::bindings::ruby_xmalloc

source ·
pub unsafe extern "C" fn ruby_xmalloc(size: size_t) -> *mut c_void
Expand description

Allocates a storage instance. It is largely the same as system malloc(), except:

  • It raises Ruby exceptions instead of returning NULL, and

  • In case of ENOMEM it tries to GC to make some room.

  • @param in size Requested amount of memory.

  • @exception rb_eNoMemError No space left for size bytes allocation.

  • @return A valid pointer to an allocated storage instance; which has at least size bytes width, with appropriate alignment detected by the underlying malloc() routine.


Note

It doesn’t return NULL.

Note

Unlike some malloc() implementations, it allocates something and returns a meaningful value even when size is equal to zero.

Warning

The return value shall be invalidated exactly once by either ruby_xfree(), ruby_xrealloc(), or ruby_xrealloc2(). It is a failure to pass it to system free(), because the system and Ruby might or might not share the same malloc() implementation.

Generated by rb-sys for Ruby 3.0.0