libUnihan  0.5.3
Macros | Functions
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.

Macros

#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.


Macro Definition 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_sizeNumber of row.
col_sizeNumber of column.
element_typeElement 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_countNumber of element to be required.
element_typeElement type to be allocated.
Returns:
A newly allocated array of element type.
#define NEW_INSTANCE (   type)    g_new(type,1)
Parameters:
typeElement type to be allocated.
Returns:
A newly allocated space for type type.

Function Documentation

void array2D_free ( void **  arrayPtr)
Parameters:
arrayPtrthe 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_sizeNumber of row.
col_sizeNumber of column.
element_sizeSize of one element.
pointer_sizeSize of element pointer.
Returns:
A two dimension array of element type.
See also:
NEW_ARRAY2D_INSTANCE()