\subsection{Dynamic Array} This section describes a dynamic array of arbitrary pointers. Dynamic means, that the array gets enlarged automatically when an index outside of the current bounds has been requested. Negative values are supported as well. The interface to this module looks like this: \begin{flushleft} \small \begin{minipage}{\linewidth} \label{scrap1} $\langle$dynarint {\footnotesize ?}$\rangle\equiv$ \vspace{-1ex} \begin{list}{}{} \item \mbox{}\verb@@\\ \mbox{}\verb@ typedef struct __SDynar *pDynar;@\\ \mbox{}\verb@/*-------------------------------------------------------------------------*/@\\ \mbox{}\verb@ pDynar CreateDynar(int iStart, int iEnd, int iGrain, @\\ \mbox{}\verb@ void (*DataFree)(void *pData));@\\ \mbox{}\verb@ void DeleteDynar(pDynar self);@\\ \mbox{}\verb@/*------------------------------------------------------------------------*/@\\ \mbox{}\verb@ int DynarPut(pDynar self, int iIndex, void *pData);@\\ \mbox{}\verb@ int DynarPutCopy(pDynar self, int iIndex, void *pData, int iDataLen);@\\ \mbox{}\verb@ int DynarReplace(pDynar self, int iIndex, void *pData, int iDatLen);@\\ \mbox{}\verb@ @\\ \mbox{}\verb@ int DynarGet(pDynar self, int iIndex, void **pData);@\\ \mbox{}\verb@ int DynarGetCopy(pDynar self, int iIndex, void *pData, int iDataLen);@\\ \mbox{}\verb@@\\ \mbox{}\verb@@$\diamond$ \end{list} \vspace{-1ex} \footnotesize\addtolength{\baselineskip}{-1ex} \begin{list}{}{\setlength{\itemsep}{-\parsep}\setlength{\itemindent}{-\leftmargin}} \item Macro referenced in scrap ?. \end{list} \end{minipage}\\[4ex] \end{flushleft} If not stated otherwise, all functions return 1 on success and 0 on failure. \begin{description} \item[CreateDynar] creates a new dynamic array. On success a pointer to a new dynamic array is returned, else NULL. The parameters are: iStart, the initial start index of the array, iEnd, the initial end index of the array, iGrain, the packet of new space to allocate when the array is enlarged dynamically, DataFree, a function which takes a pointer to one of the data items stored in the dynamic array and the free's all the memory associated with the data item. DataFree will be used automatically by Dynar for releasing memory when data items are replaced or the whole array is deleted. \item[DeleteDynar] removes the dynamic arary from memory. The pointer to self will point to rubbish afterwards and shall not be used. \item[DynarPut] puts the pointer pData at position iIndex in the dynamic array. pData needs to be allocated from dynamic memory, otherwise you'll experience core dumps. A data item which was previously at the position denoted by iIndex will be freed. \item[DynarPutCopy] does the same as DynarPut, but copies the data item. iDataLen bytes of new memory will be allocated and the data from pData be put into it. Then this will be entered into the dynamic array at position iIndex. \item[DynarReplace] replaces the data at iIndex by the data pointed to by pData by a memcpy. If there was no data defined previously, this call has the same effect as DynarPutCopy. \item[DynarGet] retrieves the pointer pData at position iIndex from the dynamic array. \item[DynarGetCopy] copies iDataLen bytes from the data at position iIndex into the buffer pData. pData must be large enough to hold iDataLen bytes. \end{description} Nowe, here is the definition of the internal datastructure for the dynamic array class. \begin{flushleft} \small \begin{minipage}{\linewidth} \label{scrap2} $\langle$dynardat {\footnotesize ?}$\rangle\equiv$ \vspace{-1ex} \begin{list}{}{} \item \mbox{}\verb@@\\ \mbox{}\verb@ typedef struct __SDynar {@\\ \mbox{}\verb@ int iStart;@\\ \mbox{}\verb@ int iEnd;@\\ \mbox{}\verb@ int iGrain;@\\ \mbox{}\verb@ void **pArray;@\\ \mbox{}\verb@ void (*DataFree)(void *pData);@\\ \mbox{}\verb@ } Dynar;@\\ \mbox{}\verb@ @\\ \mbox{}\verb@ @\\ \mbox{}\verb@@$\diamond$ \end{list} \vspace{-1ex} \footnotesize\addtolength{\baselineskip}{-1ex} \begin{list}{}{\setlength{\itemsep}{-\parsep}\setlength{\itemindent}{-\leftmargin}} \item Macro referenced in scrap ?. \end{list} \end{minipage}\\[4ex] \end{flushleft} \begin{flushleft} \small \begin{minipage}{\linewidth} \label{scrap3} \verb@"sdynar.h"@ {\footnotesize ? }$\equiv$ \vspace{-1ex} \begin{list}{}{} \item \mbox{}\verb@@\\ \mbox{}\verb@/*---------------------------------------------------------------------------@\\ \mbox{}\verb@ D Y N A M I C A R R A Y@\\ \mbox{}\verb@@\\ \mbox{}\verb@ This file describes the interface to a dynamic array module for pointers.@\\ \mbox{}\verb@ This sort of array resizes dynamically.@\\ \mbox{}\verb@ @\\ \mbox{}\verb@ Mark Koennecke, September 1997@\\ \mbox{}\verb@@\\ \mbox{}\verb@ copyright: see copyright.h@\\ \mbox{}\verb@@\\ \mbox{}\verb@-----------------------------------------------------------------------------*/@\\ \mbox{}\verb@#ifndef SICSDYNAR@\\ \mbox{}\verb@#define SICSDYNAR@\\ \mbox{}\verb@@$\langle$dynarint {\footnotesize ?}$\rangle$\verb@@\\ \mbox{}\verb@#endif@\\ \mbox{}\verb@@\\ \mbox{}\verb@@$\diamond$ \end{list} \vspace{-2ex} \end{minipage}\\[4ex] \end{flushleft} \begin{flushleft} \small \begin{minipage}{\linewidth} \label{scrap4} \verb@"sdynar.i"@ {\footnotesize ? }$\equiv$ \vspace{-1ex} \begin{list}{}{} \item \mbox{}\verb@@\\ \mbox{}\verb@/*----------------------------------------------------------------------------@\\ \mbox{}\verb@ D Y N A M I C A R R A Y@\\ \mbox{}\verb@@\\ \mbox{}\verb@ This file defines the internal data structure used by the dynamic@\\ \mbox{}\verb@ array module.@\\ \mbox{}\verb@ @\\ \mbox{}\verb@ More info: see sdynar.h@\\ \mbox{}\verb@-----------------------------------------------------------------------------*/@\\ \mbox{}\verb@@$\langle$dynardat {\footnotesize ?}$\rangle$\verb@@\\ \mbox{}\verb@@$\diamond$ \end{list} \vspace{-2ex} \end{minipage}\\[4ex] \end{flushleft}