|MALLOC(3C)||Standard C Library Functions||MALLOC(3C)|
size_t nelem, size_t
size_t oldnelem, size_t
newnelem, size_t elsize);
free() functions provide a simple, general-purpose memory allocation package. The
malloc() function returns a pointer to a block of at least size bytes suitably aligned for any use. If the space assigned by
malloc() is overrun, the results are undefined.
The argument to
free() is a pointer to a
block previously allocated by
free() is executed, this space is made available for
further allocation by the application, though not returned to the system.
Memory is returned to the system only upon termination of the application.
If ptr is a null pointer, no action occurs. If a
random number is passed to
free(), the results are
freezero() function is similar to the
free() function except it ensures memory is
explicitly discarded. If ptr is
NULL, no action occurs. If ptr
NULL, the size argument
must be equal or smaller than the size of the earlier allocation that
guarantees the memory range starting at ptr with
length size is discarded while deallocating the whole
object originally allocated.
calloc() function allocates space for
an array of nelem elements of size
elsize. The space is initialized to zeros.
memalign() function allocates
size bytes on a specified alignment boundary and
returns a pointer to the allocated block. The value of the returned address
is guaranteed to be an even multiple of alignment. The
value of alignment must be a power of two and must be
greater than or equal to the size of a word.
realloc() function changes the size of
the block pointed to by ptr to
size bytes and returns a pointer to the (possibly
moved) block. The contents will be unchanged up to the lesser of the new and
old sizes. If the new size of the block requires movement of the block, the
space for the previous instantiation of the block is freed. If the new size
is larger, the contents of the newly allocated portion of the block are
unspecified. If ptr is
realloc() behaves like
malloc() for the specified size. If
size is 0 and ptr is not a null
pointer, the space pointed to is freed.
reallocf() function behaves in the
same way as
realloc() except that the passed pointer
is freed automatically on failure.
reallocarray() function is similar to
realloc(), but operates on
nelem elements of size elsize
and checks for overflow in
recallocarray() function is similar to
reallocarray() except it ensures newly allocated
memory is cleared similar to
oldnelem is ignored and the call is equivalent to
calloc(). If ptr is not
NULL, oldnelem must be a value
such that oldnelem*elsize is the
size of the earlier allocation that returned ptr,
otherwise the behaviour is undefined.
valloc() function has the same effect
malloc(), except that the allocated memory will
be aligned to a multiple of the value returned by
alloca() function allocates
size bytes of space in the stack frame of the caller,
and returns a pointer to the allocated block. This temporary space is
automatically freed when the caller returns. If the allocated block is
beyond the current stack limit, the resulting behavior is undefined.
If there is no available memory,
valloc() return a null pointer.
realloc() is called with
size > 0 and returns
the block pointed to by ptr is left intact. By
reallocf() is called with
size > 0 and returns
the block pointed to by ptr will have been freed.
If size, nelem, or
elsize is 0, either a null pointer or a unique pointer
that can be passed to
free() is returned.
recallocarray() returns unsuccessfully,
errno will be set to indicate the error. The
functions do not set errno.
reallocarray() functions will fail if:
recallocarray() function will fail
NULLand multiplying oldnelem and elsize results in integer overflow.
valloc() but should instead use
malloc() or mmap(2). On systems with a large page size, the number of successful
valloc() operations might be 0.
These default memory allocation routines are safe for use in multithreaded applications but are not scalable. Concurrent accesses by multiple threads are single-threaded through the use of a single lock. Multithreaded applications that make heavy use of dynamic memory allocation should be linked with allocation libraries designed for concurrent access, such as libumem(3LIB) or libmtmalloc(3LIB). Applications that want to avoid using heap allocations (with brk(2)) can do so by using either libumem(3LIB) or libmapmalloc(3LIB). The allocation libraries libmalloc(3LIB) and libbsdmalloc(3LIB) are available for special needs.
Comparative features of the various allocation libraries can be found in the umem_alloc(3MALLOC) manual page.
valloc() functions are Standard.
recallocarray() functions are
alloca() functions are Stable.
alloca() function is machine-,
compiler-, and most of all, system-dependent. Its use is strongly
|September 12, 2019||OmniOS|