AllocateDynArrayEntry

Allocates an entry in a dynamic array

Local Servers:nonblocking
Remote Servers:N/A
Classification:3.x, 4.x, 5.x, 6.x
Service:Advanced

Syntax

  #include <nwdynarr.h>  
   
  int AllocateDynArrayEntry  (  
     T_DYNARRAY_BLOCK    * dabP);
  

Parameters

dabP

(IN) Points to the T_DYNARRAY_BLOCK structure containing the Dynamic Array Block (DAB).

Return Values

This function returns the index of the entry (a value of 0 or greater) if successful. Otherwise, it returns an error code:

-1

EFAILURE

Remarks

Call the AllocateDynArrayEntry function to allocate additional entries in the dynamic array. The dynamic array can be increased in size, but not decreased.

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 developer-defined function.

DABgrowAmount is the number of elements by which to increase the dynamic array when more elements are needed.

The DAB structure can be declared and initialized by standard C methods, or the following macro can be used:

  GEN_DYNARRAY_BLOCK(  elementType,  varName, defDec ) 
  

Where elementType is the C type of the element, such as int, struct, and so on. varName is the name of the variable declared as a dynamic array. defDec can be DECLARE, DEFINE, or INIT, as follows:

DELARE

Declares the varName as the type of DAB specified. Generates the following:

  struct varName##Struct varName
  
DEFINE ( realloc , growAmount )

Defines and initializes varName as the type of DAB specified. Generates the following:

  struct varName##Struct 
  { 
     elementType   *DABarrayP; 
     int           DABnumSlots; 
     int           DABelementSize; 
     void          *(*DABrealloc) (void *, size_t); 
     int           DABgrowAmount; 
     int           DABnumEntries; 
  } varName = {NULL, 0, elementSize, realloc, growAmount, 0}
  
INIT ( realloc , growAmount )

Initializes an already-defined DAB. Generates the following:

  struct varName##Struct varName =  
          {NULL, 0, elementSize, realloc, growAmount, 0}
  

The parameters for DEFINE and INIT are as follows:

realloc

Specifies the reallocation function to use when expanding the dynamic array. Normally, this would be realloc.

growAmount

Specifies the amount to expand the dynamic array by if AllocateDynArrayEntry expands the array.

See Also

AllocateGivenDynArrayEntry, DeallocateDynArrayEntry