allocate.h File Reference

Convenient macros and functions for allocating objects, arrays or 2D arrays. More...

#include <stdlib.h>
#include <glib.h>

Go to the source code of this file.

Defines

#define NEW_INSTANCE(type)   g_new(type,1)
 Allocate a new instance for type type.
#define NEW_ARRAY_INSTANCE(element_count, element_type)   g_new(element_type,element_count)
 Allocate a new instance array for type type.
#define NEW_ARRAY2D_INSTANCE(row_size, col_size, element_type)   (element_type**) array2D_new(row_size,col_size,sizeof(element_type),sizeof(element_type*));
 Allocate a new two dimension array.

Functions

void ** array2D_new (size_t row_size, size_t col_size, size_t element_size, size_t pointer_size)
 Allocate a new two dimension array.
void array2D_free (void **arrayPtr)
 Free the 2D array create by NEW_ARRAY2D_INSTANCE().


Detailed Description

This header file lists the macros and functions for allocating instance, 1-D and 2-D instance array of given type.

Define Documentation

#define NEW_ARRAY2D_INSTANCE ( row_size,
col_size,
element_type   )     (element_type**) array2D_new(row_size,col_size,sizeof(element_type),sizeof(element_type*));

Parameters:
row_size Number of row.
col_size Number of column.
element_type Element type to be allocated.
Returns:
A two dimension array of element type.

#define NEW_ARRAY_INSTANCE ( element_count,
element_type   )     g_new(element_type,element_count)

Parameters:
element_count Number of element to be required.
element_type Element type to be allocated.
Returns:
A newly allocated array of element type.

#define NEW_INSTANCE ( type   )     g_new(type,1)

Parameters:
type Element type to be allocated.
Returns:
A newly allocated space for type type.


Function Documentation

void array2D_free ( void **  arrayPtr  ) 

Parameters:
arrayPtr the 2D array to be freed.

void** array2D_new ( size_t  row_size,
size_t  col_size,
size_t  element_size,
size_t  pointer_size 
)

Note that NEW_ARRAY2D_INSTANCE() is a more convenient wrapper macro of this function, so call that macro instead.

Parameters:
row_size Number of row.
col_size Number of column.
element_size Size of one element.
pointer_size Size of element pointer.
Returns:
A two dimension array of element type.
See also:
NEW_ARRAY2D_INSTANCE()


Generated on Tue Jan 13 10:49:25 2009 for libUnihan by  doxygen 1.5.7.1