Golem  v0.1.1
Generic Operating system Libraries for Embedded Multitasking
 All Data Structures Files Functions Variables Pages
/home/ruud/Engineering/software/projects/golem-project-code/trunk/glm_heap.h File Reference

This file is a wrapper for all heap-related operations. More...

#include <stdlib.h>
#include <stdbool.h>
#include "glm_intbase.h"

Go to the source code of this file.

Data Structures

struct  heap_stats_t
 Container for storing a heap user's usage statistics. More...
 

Functions

void heap_reset ()
 Resets the heap functionality. More...
 
bool heap_create_hid (char *a_name, heap_id_t *a_heap_id)
 Create a new heap ID. More...
 
bool heap_stats (heap_id_t a_heap_id, heap_stats_t *a_heap_stats)
 Get heap statistics for the given heap user. More...
 
void heap_totals (heap_stats_t *a_heap_totals)
 Get overall heap statistics. More...
 
void * heap_malloc (heap_id_t a_id, size_t a_size)
 Allocate a_size bytes of heap memory for the given heap user. More...
 
void * heap_calloc (heap_id_t a_id, size_t a_nr_elements, size_t a_size)
 Allocate heap memory for an array of elements. More...
 
void * heap_realloc (void *a_ptr, size_t a_size)
 Re-allocate memory for the given object. More...
 
void heap_free (void *a_ptr)
 Free the memory occupied by the given object. More...
 
size_t heap_sizeof (void *a_ptr)
 Get the size of the given object. More...
 
heap_id_t heap_get_id (void *a_ptr)
 Get heap ID of object. More...
 
void heap_transfer_owner (void *a_ptr, heap_id_t a_id)
 Transfer ownership of an object. More...
 

Detailed Description

This file is a wrapper for all heap-related operations.

It collects heap memory usage statistics for a software component. This may be useful when tracing back problems to memory leaks.

Author
Ruud Beukema

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Todo:

Verify functioning of this component.

Add an example of use to the Doxygen documentation

Definition in file glm_heap.h.

Function Documentation

void* heap_calloc ( heap_id_t  a_id,
size_t  a_nr_elements,
size_t  a_size 
)

Allocate heap memory for an array of elements.

Parameters
a_idHeap-ID
a_nr_elementsSize of the array
a_sizeSize of a single array element
Returns
NULL if allocation fails. Otherwise a valid pointer to the newly allocated memory.

Definition at line 151 of file glm_heap.c.

bool heap_create_hid ( char *  a_name,
heap_id_t *  a_heap_id 
)

Create a new heap ID.

Parameters
a_namePointer to the start of the name name of the calling software component. Make sure the name is '\0'- terminated!
a_heap_idPointer to variable to which the created heap-ID is to be stored.
Returns
TRUE if creation was successful, FALSE if not.

Definition at line 62 of file glm_heap.c.

void heap_free ( void *  a_ptr)

Free the memory occupied by the given object.

Parameters
a_ptrPointer to the object to be freed.

Definition at line 228 of file glm_heap.c.

heap_id_t heap_get_id ( void *  a_ptr)

Get heap ID of object.

Parameters
a_ptrPointer to object which heap ID is requested.
Returns
The object's heap ID

Definition at line 260 of file glm_heap.c.

void* heap_malloc ( heap_id_t  a_id,
size_t  a_size 
)

Allocate a_size bytes of heap memory for the given heap user.

Parameters
a_idHeap-ID
a_sizeNumber of bytes to allocate.
Returns
NULL if allocation fails. Otherwise a valid pointer to the newly allocated memory.
Examples:
example_glm_list.c.

Definition at line 118 of file glm_heap.c.

void* heap_realloc ( void *  a_ptr,
size_t  a_size 
)

Re-allocate memory for the given object.

Parameters
a_ptrPointer to the object to be reallocated.
a_sizeRequested new size. If size is 0, all memory will be freed. If size is equal to the current size, no action is taken.
Returns
NULL if allocation fails. Otherwise a valid pointer to the newly allocated memory.

Definition at line 177 of file glm_heap.c.

void heap_reset ( )

Resets the heap functionality.

All registered heap-ID's will be unregistered and their statistics will be cleared.

Definition at line 51 of file glm_heap.c.

size_t heap_sizeof ( void *  a_ptr)

Get the size of the given object.

Parameters
a_ptrPointer to the object
Returns
The size of the object pointed to by a_ptr.

Definition at line 249 of file glm_heap.c.

bool heap_stats ( heap_id_t  a_heap_id,
heap_stats_t a_heap_stats 
)

Get heap statistics for the given heap user.

Parameters
a_heap_idThe caller's heap-ID.
a_heap_statsPointer to variable to which to store a copy of the heap statistics.
Returns
TRUE if given heap-ID is valid and a_heap_stats hold valid stats or FALSE if not.

Definition at line 94 of file glm_heap.c.

void heap_totals ( heap_stats_t a_heap_totals)

Get overall heap statistics.

Parameters
a_heap_totalsPointer to variable in which to store copy of the overall heap statistics.

Definition at line 110 of file glm_heap.c.

void heap_transfer_owner ( void *  a_ptr,
heap_id_t  a_id 
)

Transfer ownership of an object.

Changes the heap ID of the given object to an other heap ID.

Parameters
a_ptrPointer to the object.
a_idHeap ID to be given to the object.

Definition at line 271 of file glm_heap.c.