The C Utility Toolkit
Main Page | Data Structures | File List | Data Fields | Globals

array.c File Reference

#include <cutk/array.h>
#include <string.h>

Defines

#define aryesize(x)   ((*((array_type**)(void*)(x))-1)->esize)

Functions

void * aryalloc_ (size_t esize)
void * aryallocsize_ (size_t esize, size_t size)
void aryfree (void *ary)
int aryreserve (void *ary, size_t max)
int aryresize (void *ary, size_t size)
int aryappend (void *ary, const void *element)
int aryinsert (void *ary, size_t index)
int aryerase (void *ary, size_t index)
int aryfasterase (void *ary, size_t index)
void * arydup (const void *ary)
int arycpy (void *dest, const void *src)
int arycat (void *dest, const void *src)

Define Documentation

#define aryesize  )     ((*((array_type**)(void*)(x))-1)->esize)
 


Function Documentation

void* aryalloc_ size_t  esize  ) 
 

Allocate a new empty array. Normally this function is not called directly. Use the aryalloc() macro instead. This allows you to specify the element type rather than the element size. Example: "int* array = aryalloc(int);"

Parameters:
esize Element size. This is the size (in bytes) of each element in the array. This is normally just the sizeof(ElementType).
Returns:
This returns a pointer to the array data (not the array structure) or NULL on failure.

void* aryallocsize_ size_t  esize,
size_t  size
 

Allocate a new array of a specified size. Normally this function is not called directly. Use the aryallocsize() macro instead. Example: "int* array = aryallocsize(int, 2000);"

Parameters:
esize Element size. This is the size (in bytes) of each element in the array. This is normally just the sizeof(ElementType).
size Number of items in array
Returns:
This returns a pointer to the array data (not the array structure) or NULL on failure.

int aryappend void *  ary,
const void *  element
 

This adds and copies a new element to the end of the array.

Parameters:
ary Pointer to an array pointer
element This value is copied into the new value at the end of the array
Returns:
0 on success; non-zero on failure

int arycat void *  dest,
const void *  src
 

Appends the source array to the end of the destination

Parameters:
dest Pointer to destination array pointer
src Pointer to source array pointer
Returns:
0 on success; non-zero on failure

int arycpy void *  dest,
const void *  src
 

This copies an array. This is just a convenient way to do an aryfree() followed by arydup().

Parameters:
dest Pointer to destination array pointer
src Pointer to source array pointer
Returns:
0 on success; non-zero on failure

void* arydup const void *  ary  ) 
 

This duplicates an array. The new array will use the minimum amount of memory necessary to hold all the elements in the array.

Parameters:
ary Pointer to an array pointer
i Element index number to erase
Returns:
Pointer to new array (same as aryalloc)

int aryerase void *  ary,
size_t  index
 

int aryfasterase void *  ary,
size_t  index
 

void aryfree void *  ary  ) 
 

This releases all memory held by an array.

Parameters:
ary Pointer to an array pointer

int aryinsert void *  ary,
size_t  index
 

Inserts a new element at position "index"

Parameters:
ary Pointer to an array pointer
index Element index number to insert before
Returns:
0 on success; non-zero on failure

int aryreserve void *  ary,
size_t  max
 

This preallocates memory for a certain maximum number of elements. Note that this does not change the size of the array unless max is less than the current size of the array.

Parameters:
ary Pointer to an array pointer
max Number of elements to preallocate
Returns:
0 on success; non-zero on failure

int aryresize void *  ary,
size_t  size
 

This resizes an array. Note that this does not free any memory held by the array if the size is smaller than the current size.

Parameters:
ary Pointer to an array pointer
size New size of array
Returns:
0 on success; non-zero on failure


Generated on Wed Jan 12 13:13:42 2005 for CUTK by doxygen 1.3.7