gCAD3D 2.40
ut_memTab.h File Reference

Go to the source code of this file.

Macros

#define def_MemTab(vTyp1)
 
#define typedef_MemTab(vTyp1)   def_MemTab(vTyp1) MemTab_##vTyp1
 template for the typedef: More...
 
#define MemTab(vTyp1)   MemTab_##vTyp1
 template for the typename: More...
 
#define _MEMTAB_NUL   {NULL, 0, 0, 0}
 
#define MEMTAB_tmpSpc_get(mtb1, rTot)
 
#define MEMTAB_tmpSpc_free(mtb1)   if((mtb1)->spcTyp < 2) free ((mtb1)->data);
 MEMTAB_tmpSpc_free free memSpace from MEMTAB_tmpSpc_get. More...
 
#define MEMTAB__(mtb, irec)   (&((mtb)->data[irec]))
 
#define MEMTAB_IND(mtb)   ((mtb)->rNr)
 
#define MEMTAB_RESET_IND(mtb)   ((mtb)->rNr=0)
 
#define MEMTAB_RMAX(mtb)   ((mtb)->rMax)
 
#define MEMTAB_RSIZ(mtb)   ((mtb)->rSiz)
 
#define MEMTAB_RFREE(mtb)   ((mtb)->rMax - (mtb)->rSiz)
 
#define MEMTAB_DAT(mtb)   ((mtb)->data)
 
#define MEMTAB_POS(mtb)   (&((mtb)->data[(mtb)->rNr]))
 
#define MEMTAB_IND_POS(mtb, pos)   (((char*)pos - (char*)(mtb)->data) / (mtb)->rSiz)
 
#define MEMTAB_IS_EMPTY(mtb)   (mtb)->data == NULL
 

Functions

 def_MemTab (void) MemTab
 default-typedef (mit void *data) More...
 
int MemTab_ini (void *memTab, int rSiz, int typ, int incSiz)
 
int MemTab_add (void *memTab, long *spcOff, void *objDat, int recNr, int mode)
 
void MEMTAB_tmpSpc_get (MemTab *memTab, int rTot)
 
void MEMTAB_tmpSpc_free (MemTab *)
 
int MEMTAB_IND (MemTab *)
 
int MEMTAB_RMAX (MemTab *)
 
int MEMTAB_RSIZ (MemTab *)
 
void * MEMTAB__ (MemTab *memTab, int ind)
 
void * MEMTAB_DAT (MemTab *)
 
void * MEMTAB_POS (MemTab *)
 
int MEMTAB_IND_POS (MemTab *, void *)
 

Macro Definition Documentation

#define def_MemTab (   vTyp1)
Value:
typedef struct {vTyp1 *data; int rMax, rNr, rSiz;\
unsigned char typ, incSiz, use, spcTyp;}
int typ
Definition: xa_tra.c:151
* Typ_MemTab - template for the typedef:
* data startpos of memspc; typ = template-parameter # 1
* rMax max. nr of records; size of data is (rMax * rSiz) bytes
* rNr nr of used records in data
* rSiz recordsize in bytes
* typ type of data-records; for info only.
* incSiz if Memspc is too small: add UTI_round_b2i(incSiz * rSiz)
* UINT_8_MAX = cannot realloc (fixed space)
* use application-specific
* spcTyp 0=malloc-type=can-reallocate,must-free;
* 1=fixed-CANNOT-reallocate;must-free;
* 2=fixed-CANNOT-reallocate;must-NOT-free;
* 3=stack,CANNOT-reallocate,must-NOT-free;
*
#define typedef_MemTab (   vTyp1)    def_MemTab(vTyp1) MemTab_##vTyp1

template for the typedef:

#define MemTab (   vTyp1)    MemTab_##vTyp1

template for the typename:

#define _MEMTAB_NUL   {NULL, 0, 0, 0}
#define MEMTAB_tmpSpc_get (   mtb1,
  rTot 
)
Value:
(mtb1)->data=NULL;\
(mtb1)->rSiz=sizeof(*(mtb1)->data);\
(mtb1)->rNr=(rTot)*(mtb1)->rSiz;\
if((mtb1)->rNr < SPC_MAX_STK) (mtb1)->data = alloca ((mtb1)->rNr);\
if(!(mtb1)->data) {\
(mtb1)->data = malloc ((mtb1)->rNr);\
(mtb1)->spcTyp = 0;\
(mtb1)->incSiz = (mtb1)->rNr / 2;\
} else {\
(mtb1)->spcTyp = 3;\
(mtb1)->incSiz = UINT_8_MAX; }\
(mtb1)->rMax = rTot;\
(mtb1)->rNr = 0;
#define UINT_8_MAX
Definition: ut_types.h:38
#define SPC_MAX_STK
Definition: ut_mem.h:6
* MEMTAB_tmpSpc_get get memspace for rTot records
* memspace exists only until active function returns.
* memspace MUST BE FREED at end of active function (MEMTAB_tmpSpc_free)
* Example:
* MemTab(int) mti1; // memspc for int's
* MEMTAB_tmpSpc_get (&mti1, 1000); // get space for 1000 int's
* ia = MEMTAB_DAT(&mti1); // get data-block-address
* for(i1=0;i1<1000;++i1) ia[i1] = i1; // store data
* MEMTAB_IND(&mtd1) = 1000; // set data 0-999 used
* ...
* MEMTAB_tmpSpc_free (&mti1); // free data
*
#define MEMTAB_tmpSpc_free (   mtb1)    if((mtb1)->spcTyp < 2) free ((mtb1)->data);

MEMTAB_tmpSpc_free free memSpace from MEMTAB_tmpSpc_get.

#define MEMTAB__ (   mtb,
  irec 
)    (&((mtb)->data[irec]))
#define MEMTAB_IND (   mtb)    ((mtb)->rNr)
#define MEMTAB_RESET_IND (   mtb)    ((mtb)->rNr=0)
#define MEMTAB_RMAX (   mtb)    ((mtb)->rMax)
#define MEMTAB_RSIZ (   mtb)    ((mtb)->rSiz)
#define MEMTAB_RFREE (   mtb)    ((mtb)->rMax - (mtb)->rSiz)
#define MEMTAB_DAT (   mtb)    ((mtb)->data)
#define MEMTAB_POS (   mtb)    (&((mtb)->data[(mtb)->rNr]))
#define MEMTAB_IND_POS (   mtb,
  pos 
)    (((char*)pos - (char*)(mtb)->data) / (mtb)->rSiz)
#define MEMTAB_IS_EMPTY (   mtb)    (mtb)->data == NULL

Function Documentation

def_MemTab ( void  )

default-typedef (mit void *data)

int MemTab_ini ( void *  memTab,
int  rSiz,
int  typ,
int  incSiz 
)
* MemTab_ini init memory-table; if already in use: clear.
* use MemTab for a list of records;
* use Memspc for a different types of records in the same memoryblock.
*
* INPUT:
* rSiz recordsize in bytes
* typ info; Typ_PT=Point Typ_Int4=int Typ_Float8=double Typ_Int1=char;
* incSiz nr of records to increment memTab;
* if Memspc is too small: add UTI_round_b2i(incSiz * rSiz)
*
* Examples:
* MemTab(int) MIFA = _MEMTAB_NUL;
* MemTab_ini (&MIFA, sizeof(int), Typ_Int4, 1000);
* or:
* static MemTab(int) MIFA = {NULL, 0, 0, sizeof(int), Typ_Int4, 10, 0, 0};
* // 10: UTI_round_b2i(10) = 1024 records to add when reallocating
*
int MemTab_add ( void *  memTab,
long *  spcOff,
void *  objDat,
int  recNr,
int  mode 
)
* MemTab_add save/check/reserve in memSpc; malloc/realloc if necessary.
* struct must be initialized with MemTab_ini; free it with MemTab_free.
* Fixed Recordsizes only !
*
* Input:
* memTab where to store data; must have type according to objDat.
* objDat data to be saved in memSpc (NULL if mode=1 or 2)
* recNr nr of records to be allocated / saved
* mode 0=save (get space, save data, incr. counter)
* 1=reserve (get space and add <recNr> to internal counter)
* 2=check (now MT has at least <recNr> free records)
* 4=save; but create <recNr> copies of record <objDat>
* Output:
* memTab->rNr nr of records already in use (including objDat)
* spcOff displacement-offset; 0: no reallocate.
* RetCode
* 0 OK
* 1 OK after reallocate
* -1 outOfMemory-Error.
*
* memTab:
* memTab->rMax nr of records already allocated
* memTab->rNr nr of records already in use
* memTab->rSiz recordsize in bytes
*
* Ablauf:
* if (recNr > 0) get space for <recNr> records.
* else get space for <recNrFree> records.
* if (objDat == NULL) do not save, do malloc/realloc.
* recNrFree = UTI_round_b2i(memTab->incSiz)
*
* Examples:
* // typedef_MemTab(Point);
* MemTab(Point) pa2D = _MEMTAB_NUL;
* ips = MEMTAB_IND (&ts1->pa2D); // get next free position
* irc = MemTab_add (&pa2D, &ld, NULL, ptNr, 1); // reserve pNr points in pa2D
* pa = MEMTAB_DAT (&ts1->pa2D); // get datablock of points
* irc = PRCV_get_dbo_1 (&pa[ips]); // get points & save in pa2D
*
void MEMTAB_tmpSpc_get ( MemTab memTab,
int  rTot 
)
void MEMTAB_tmpSpc_free ( MemTab )
int MEMTAB_IND ( MemTab )
int MEMTAB_RMAX ( MemTab )
int MEMTAB_RSIZ ( MemTab )
void* MEMTAB__ ( MemTab memTab,
int  ind 
)
void* MEMTAB_DAT ( MemTab )
void* MEMTAB_POS ( MemTab )
int MEMTAB_IND_POS ( MemTab ,
void *   
)