maheap.h File Reference


Detailed Description

Dynamic memory allocation.

#include <ma.h>

Typedefs

typedef void(* malloc_handler )(int size)
typedef void *(* malloc_hook )(int size)
typedef void(* free_hook )(void *ptr)
typedef void *(* realloc_hook )(void *ptr, int size)
typedef int(* block_size_hook )(void *ptr)

Functions

void * malloc (int size)
 Allocate uninitialized memory. Allocates memory from the mosync heap.
void * calloc (int num_elem, int size_elem)
 Allocate initialized memory. Allocates memory from the mosync heap and sets the contents to null.
void free (void *mem)
 Deallocate memory. Deallocates memory from the mosync heap.
void * realloc (void *old, int size)
 Reallocate memory. Attempts to resize a previously allocated block of memory. If successful, returns a pointer to the resized memory block. The pointer may be identical to the old, or different. Returns NULL on failure, leaving the old memory block untouched.
void default_malloc_handler (int size) __attribute__((noreturn))
malloc_handler set_malloc_handler (malloc_handler)
malloc_hook set_malloc_hook (malloc_hook hook)
free_hook set_free_hook (free_hook hook)
realloc_hook set_realloc_hook (realloc_hook hook)
block_size_hook set_block_size_hook (block_size_hook hook)
void override_heap_init_crt0 (char *start, int length)


Typedef Documentation

typedef void(* malloc_handler)(int size)
 

typedef void*(* malloc_hook)(int size)
 

typedef void(* free_hook)(void *ptr)
 

typedef void*(* realloc_hook)(void *ptr, int size)
 

typedef int(* block_size_hook)(void *ptr)
 


Function Documentation

void* malloc int  size  ) 
 

Allocate uninitialized memory. Allocates memory from the mosync heap.

Parameters:
size The number of bytes to allocate.
Returns:
Returns a pointer to the allocated memory.
See also:
calloc

free

Note:
The maximum heap size depends on the heapsize setting in the build

void* calloc int  num_elem,
int  size_elem
 

Allocate initialized memory. Allocates memory from the mosync heap and sets the contents to null.

Parameters:
num_elem The number of elements of memory to allocate.
size_elem The size of each elements of memory.
Returns:
Returns a pointer to the allocated memory.
See also:
malloc

free

Note:
The maximum heap size depends of the datasize setting in the build.

void free void *  mem  ) 
 

Deallocate memory. Deallocates memory from the mosync heap.

Parameters:
mem A pointer to the memory to deallocate.
See also:
malloc

calloc

void* realloc void *  old,
int  size
 

Reallocate memory. Attempts to resize a previously allocated block of memory. If successful, returns a pointer to the resized memory block. The pointer may be identical to the old, or different. Returns NULL on failure, leaving the old memory block untouched.

Parameters:
old The old block of memory.
size The requested size.

void default_malloc_handler int  size  ) 
 

Calls maPanic().

malloc_handler set_malloc_handler malloc_handler   ) 
 

Sets the function to be called in case malloc() fails. Setting this to NULL disables the handler system. It is initially set to default_malloc_handler().

Returns:
The previous handler.
See also:
malloc

malloc_hook set_malloc_hook malloc_hook  hook  ) 
 

Sets a function to be called instead of the standard malloc(). The malloc_handler system will still work after a hook has been set.

Parameters:
hook A function to allocate memory or return NULL.
Returns:
The old hook.

free_hook set_free_hook free_hook  hook  ) 
 

Sets a function to be called instead of the standard free().

Parameters:
hook A function to free memory.
Returns:
The old hook.

realloc_hook set_realloc_hook realloc_hook  hook  ) 
 

Sets a function to be called instead of the standard realloc().

Parameters:
hook A function to increase the size of an existing memory cell.
Returns:
The old hook.

block_size_hook set_block_size_hook block_size_hook  hook  ) 
 

Sets a function to be called from free to get the size of the block.

Parameters:
hook A function to retrieve the size of a user allocated block.
Returns:
The old hook.

void override_heap_init_crt0 char *  start,
int  length
 

This function is not implemented. You may implement it. If you do, it will be called at the beginning of execution, instead of the standard heap initialization function, before C++ static constructors and MAMain.

You must call set_malloc_hook() and set_free_hook() from this function, or the heap will be broken and malloc() will not work. You must also call set_realloc_hook(), if your program uses realloc().

This function will only be called on the MAPIP GCC target, because the optional call to this function relies on a special feature of pipe-tool.

Parameters:
start The address of the start of the heap.
length The length of the heap, in bytes.


Generated on Sat Feb 13 00:15:37 2010 for MoSync 2 beta 1 by  doxygen 1.4.6-NO