Allocates an entry in a dynamic array at a given element index
#include <nwdynarr.h> int AllocateGivenDynArrayEntry ( T_DYNARRAY_BLOCK *dabP, int ndx);
(IN) Points to a pointer to the Dynamic Array Block (DAB).
(IN) Specifies the desired 0-based element index into the dynamic array.
This function returns a value of 0 if successful. Otherwise, it returns an error code:
Use the AllocateGivenDynArrayEntry function to allocate additional entries in the dynamic array.
The array can be increased in size, but not decreased.
If the index goes beyond the number of elements in the array, the array is expanded to accommodate it. All intermediate entries are allocated and marked as available.
If an in-use memory block already exists at the specified index, it is overwritten, and 0 is returned.
DAB is a structure with the following elements:
elementType *DABarrayP; /* elementType = int,struct,typedef,..*/ int DABnumSlots; int DABelementSize; /* user-supplied */ void *(*DABrealloc) (void *, size_t); /* user-supplied */ int DABgrowAmount; /* user-supplied */ int DABnumEntries;
DABarrayP is the pointer to the dynamic array. It is referenced as varName.DABarrayP. To reference an entry of the dynamic array, the expression, varName.DABarrayP[index] is used. If the entry is a structure, one of its fields can be referenced as varName.DABarrayP[index].field.
DABrealloc is the address of the desired memory allocation function which must allow resizing. This function is normally realloc, but it can be a user-defined function.
DABgrowAmount is ignored for this function.
This structure can declared and initialized by standard C methods, or the following macro can be used:
GEN_DYNARRAY_BLOCK( elementType, varName, defDec )
See AllocateDynArrayEntry for more detailed information about this macro.