MoSync 3.3
maheap.h File Reference

Dynamic memory allocation. More...

#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. If old is NULL, a new block is allocated. If size is 0, the block is freed, and NULL is returned.
size_t heapTotalMemory (void)
size_t heapFreeMemory (void)
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)
void ansi_heap_init_crt0 (char *start, int length)
void initStackDump (void)

Detailed Description

Dynamic memory allocation.


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:
sizeThe 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

Referenced by MAUtil::HashDict< Key, Storage >::HashDict().

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_elemThe number of elements of memory to allocate.
size_elemThe 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.

Referenced by MAUtil::HashDict< Key, Storage >::operator=().

void free ( void *  mem)

Deallocate memory. Deallocates memory from the mosync heap.

Parameters:
memA 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. If old is NULL, a new block is allocated. If size is 0, the block is freed, and NULL is returned.

Parameters:
oldThe old block of memory.
sizeThe requested size.
size_t heapTotalMemory ( void  )

Returns the total size of the heap, in bytes.

size_t heapFreeMemory ( void  )

Returns the amount of available memory on the heap, in bytes.

Note:
Due to overhead, you will not be able to allocate exactly this amount.
void default_malloc_handler ( int  size)

Calls maPanic().

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

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:
hookA function to allocate memory or return NULL.
Returns:
The old hook.

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

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

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

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

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

Parameters:
hookA 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:
startThe address of the start of the heap.
lengthThe length of the heap, in bytes.
void ansi_heap_init_crt0 ( char *  start,
int  length 
)

The default heap initialization function.

See also:
override_heap_init_crt0()
void initStackDump ( void  )

Starts a system for dumping information about every call to malloc() or free(). Only available in debug builds. It is recommended to call this from override_heap_init_crt0(), in order to catch malloc() calls from static constructors.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines