AllocateGivenDynArrayEntry

Allocates an entry in a dynamic array at a given element index

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

Syntax

  #include <nwdynarr.h>  
   
  int AllocateGivenDynArrayEntry  (  
     T_DYNARRAY_BLOCK   *dabP,   
     int                 ndx); 
  

Parameters

dabP

(IN) Points to a pointer to the Dynamic Array Block (DAB).

ndx

(IN) Specifies the desired 0-based element index into the dynamic array.

Return Values

This function returns a value of 0 if successful. Otherwise, it returns an error code:

Value

Name

Description

5

ENOMEM

Not enough memory.

Remarks

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.

See Also

AllocateDynArrayEntry, DeallocateDynArrayEntry