Function rb_sys::bindings::ruby_xmalloc2
source · pub unsafe extern "C" fn ruby_xmalloc2(
nelems: size_t,
elemsiz: size_t
) -> *mut c_voidExpand description
Identical to ruby_xmalloc(), except it allocates nelems * elemsiz bytes.
This is needed because the multiplication could integer overflow. On such
situations Ruby does not try to allocate at all but raises Ruby level
exceptions instead. If there is no integer overflow the behaviour is
exactly the same as ruby_xmalloc(nelems*elemsiz).
- @param
innelems Number of elements. - @param
inelemsiz Size of an element. - @exception
rb_eNoMemErrorNo space left for allocation. - @exception
rb_eArgErrornelems*elemsizwould overflow. - @return A valid pointer to an allocated storage instance; which has at
least
nelems*elemsizbytes 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 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.
Generated by rb-sys for Ruby 3.0.0