Function rb_sys::bindings::ruby_xcalloc

source ·
pub unsafe extern "C" fn ruby_xcalloc(
nelems: size_t,
elemsiz: size_t
) -> *mut c_void
Expand description

Identical to ruby_xmalloc2(), except it zero-fills the region before it returns. This could also be seen as a routine identical to ruby_xmalloc(), except it calls calloc() instead of malloc() internally.

@param[in] nelems Number of elements. @param[in] elemsiz Size of an element. @exception rb_eNoMemError No space left for allocation. @exception rb_eArgError nelems * elemsiz would overflow. @return A valid pointer to an allocated storage instance; which has at least nelems * elemsiz bytes width, with appropriate alignment detected by the underlying calloc() routine. @note It doesn’t return NULL. @note Unlike some calloc() implementations, it allocates something and returns a meaningful value even when nelems or elemsiz or both are 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.