next up previous contents index
Next: 9.4.10 math.h: floating-point math Up: 9.4 Header Files Previous: 9.4.8 limits.h: architecture-specific limits

9.4.9 malloc.h: memory allocator definitions

   

DESCRIPTION

This header file defines common types and functions used by the minimal C library's default memory allocation functions. This header file is not a standard POSIX or X/Open CAE header file; instead its purpose is to expose the implementation of the malloc facility so that the client can fully control it and use it in arbitrary contexts.

The malloc package implements the following standard allocation routines (also defined in stdlib.h).

malloc
Allocate a chunk of memory in the caller's heap.
mustmalloc
Like malloc, but calls panic if the allocation fails.
memalign
Allocate a chunk of aligned memory.
calloc
Allocate a zero-filled chunk of memory.
mustcalloc
Like calloc, but calls panic if the allocation fails.
realloc
Changes the allocated size of a chunk of memory while preserving the contents of that memory.
free
Releases a chunk of memory.

The base C library also provides additional routines that allocate chunks of memory that are naturally aligned. The user must keep track of the size of each allocated chunk and free the memory with sfree rather than the ordinary free.

smalloc
Allocate a chunk of user-managed memory in the caller's heap.
smemalign
Allocate an aligned chunk of user-managed memory.
scalloc
Currently not implemented.
srealloc
Currently not implemented.
sfree
Free a user-managed chunk of memory previously allocated by an s* allocation.

The following are specific to the LMM implementation. They take an additional flag to allow requests for specific types of memory.

mallocf
Allocate a chunk of user-managed memory in the caller's heap.
memalignf
Allocate an aligned chunk of user-managed memory.
smallocf
Allocate a chunk of user-managed memory in the caller's heap.
smemalignf
Allocate an aligned chunk of user-managed memory.

The following functions are frequently overridden by the client OS:

morecore
Called by malloc and realloc varients when an attempt to allocate memory from the LMM fails. The default version does nothing.
mem_lock
Called to ensure exclusive access to the underlying LMM. The default version does nothing.
mem_unlock
Called when exclusive access is no longer needed. The default version does nothing.

See Section 9.5 for details on these functions.


next up previous contents index
Next: 9.4.10 math.h: floating-point math Up: 9.4 Header Files Previous: 9.4.8 limits.h: architecture-specific limits

University of Utah Flux Research Group