KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Functions
malloc.h File Reference

Standard C Malloc functionality. More...

#include <sys/cdefs.h>
#include <arch/types.h>

Go to the source code of this file.

Data Structures

struct  mallinfo
 ANSI C functions. More...
 

Macros

#define M_MXFAST   1
 
#define DEFAULT_MXFAST   64
 
#define M_TRIM_THRESHOLD   -1
 
#define DEFAULT_TRIM_THRESHOLD   (256*1024)
 
#define M_TOP_PAD   -2
 
#define DEFAULT_TOP_PAD   0
 
#define M_MMAP_THRESHOLD   -3
 
#define DEFAULT_MMAP_THRESHOLD   (256*1024)
 
#define M_MMAP_MAX   -4
 
#define DEFAULT_MMAP_MAX   65536
 

Functions

void * malloc (size_t size)
 allocate memory More...
 
void * calloc (size_t nmemb, size_t size)
 allocate memory on the heap and initialize it to 0 More...
 
void free (void *ptr)
 releases memory that was previous allocated More...
 
void * realloc (void *ptr, size_t size)
 changes the size of previously allocated memory More...
 
void * memalign (size_t alignment, size_t size)
 allocate memory aligned memory More...
 
void * valloc (size_t size)
 allocates memory aligned to the system page size More...
 
struct mallinfo mallinfo ()
 Sets tunable parameters for malloc related options. More...
 
int mallopt (int, int)
 
void malloc_stats ()
 Debug function. More...
 
int malloc_irq_safe ()
 KOS specfic calls. More...
 
int mem_check_block (void *p)
 Only available with KM_DBG. More...
 
int mem_check_all ()
 Only available with KM_DBG. More...
 

Detailed Description

Standard C Malloc functionality.

This implements standard C heap allocation, deallocation, and stats.

Author
Dan Potter

Macro Definition Documentation

#define DEFAULT_MMAP_MAX   65536
#define DEFAULT_MMAP_THRESHOLD   (256*1024)
#define DEFAULT_MXFAST   64
#define DEFAULT_TOP_PAD   0
#define DEFAULT_TRIM_THRESHOLD   (256*1024)
#define M_MMAP_MAX   -4
#define M_MMAP_THRESHOLD   -3
#define M_MXFAST   1
#define M_TOP_PAD   -2
#define M_TRIM_THRESHOLD   -1

Function Documentation

void* calloc ( size_t  nmemb,
size_t  size 
)

allocate memory on the heap and initialize it to 0

This allocates a chunk of memory of size * nmemb. In otherwords, an array with nmemb elements of size or size[nmemb].

Parameters
nmembis the amount of elements
sizethe size of each element
Returns
a pointer to the newly allocated address or NULL on errors.
See also
free
Note
the memory chunk is set to zero
NULL may be returned if nmemb or size is 0
void free ( void *  ptr)

releases memory that was previous allocated

frees the memory space that had previously been allocated by malloc or calloc.

Parameters
ptris a pointer to the address of allocated ram
Note
no action is taken if NULL is passed
calling free on the same ptr more than once should not be expected to behave in a reproducable maner as it is unpredictable.
struct mallinfo mallinfo ( )

Sets tunable parameters for malloc related options.

void* malloc ( size_t  size)

allocate memory

This allocates the specified size of bytes onto the heap. This memory is not freed automatically if the returned pointer goes out of scope. Thus you must call free to reclaim the used space when finished.

Parameters
sizeis the size in bytes to allocate
Returns
a pointer to the newly allocated address or NULL on errors.
See also
free
Note
the memory chunk is uninitialized
NULL may also be returned if size is 0
int malloc_irq_safe ( )

KOS specfic calls.

void malloc_stats ( )

Debug function.

int mallopt ( int  ,
int   
)
int mem_check_all ( )

Only available with KM_DBG.

int mem_check_block ( void *  p)

Only available with KM_DBG.

void* memalign ( size_t  alignment,
size_t  size 
)

allocate memory aligned memory

Memory of size is allocated with the address being a multiple of alignment

Parameters
alignmenta multiple of two that the memory address will be aligned to
sizethe size of the memory to allocate
Returns
a pointer to the newly allocated address (aligned to alignment) or NULL on errors
void* realloc ( void *  ptr,
size_t  size 
)

changes the size of previously allocated memory

The size of ptr is changed to size. If data has already been placed in the memory area at that location, it's preserved up to size. If size is larger then the previously allocated memory, the new area will be unititialized.

Parameters
ptrthe address pointer that's been previously returned by malloc/calloc
sizethe new size to give to the memory
Returns
a pointer to the new address
Note
if ptr is NULL the call is basically a malloc(size)
if ptr is not NULL, and size is 0 the call is basically a free(ptr)
void* valloc ( size_t  size)

allocates memory aligned to the system page size

Memory is allocated of size and is aligned to the system page size. This ends up basically being: memolign(PAGESIZE, size)

Parameters
sizethe size of the memory to allocate
Returns
a pointer to the newly allocated memory address
See also
arch/arch.h