gCAD3D 2.40
ut_memTab.c File Reference

fixed-length-records in memory: add,insert,delete, realloc. .. MemTab_ More...

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "../ut/AP_types.h"
#include "../ut/ut_memTab.h"
#include "../ut/ut_uti.h"
#include "../ut/ut_cast.h"
#include "../ut/ut_types.h"

Functions

int MemTab_spc (MemTab *memTab, void *data, int dSiz, int rSiz, int typ)
 
int MemTab_ini (void *mtbv, int rSiz, int typ, int incSiz)
 
int MemTab_add (void *mtbv, long *spcOff, void *objDat, int recNr, int mode)
 
int MemTab_sav (MemTab *memTab, long *spcOff, void *objDat, int recNr)
 
int MemTab_uniq_sav (MemTab *memTab, long *spcOff, void *objDat)
 
int MemTab_reserve (MemTab *memTab, long *spcOff, int recNr)
 
int MemTab_check (MemTab *memTab, long *spcOff, int recNr)
 
int MemTab_load (void **oTab, int *iNr, MemTab *mt)
 
int MemTab_get (void *objDat, MemTab *mt, int ipos, int recNr)
 
int MemTab_mod (MemTab *mt, void *objDat, int ipos, int recNr)
 
int MemTab_del (MemTab *mt, int ipos, int delRecNr)
 
int MemTab_ins (MemTab *mt, long *spcOff, void *objDat, int ipos, int insRecNr)
 
int MemTab_clear (MemTab *memTab)
 
int MemTab_free (MemTab *memTab)
 
int MemTab_wrf (FILE *fp1, MemTab *mt)
 
int MemTab_rdf (FILE *fp1, MemTab *mt1)
 
int MemTab_dump (MemTab *memTab, char *info)
 

Detailed Description

fixed-length-records in memory: add,insert,delete, realloc. .. MemTab_

=====================================================
List_functions_start:
MemTab_ini init memory-table, malloc
MemTab_spc init memory-table with fixed memoryspace; no realloc, free.
MEMTAB_tmpSpc_get get memspace for rTot records INLINE
MEMTAB_tmpSpc_free free memspace from MEMTAB_tmpSpc_get INLINE
MemTab_add save/check/reserve in memSpc; malloc/realloc if necessary.
MemTab_sav save objDat to memSpc; malloc/realloc if necessary.
MemTab_uniq_sav if data is uniq only: save data with MemTab_add (.. 1, 0);
MemTab_reserve reserve space to memSpc; malloc/realloc if necessary.
MemTab_check check free space to memSpc; malloc/realloc if necessary.
MemTab_ins insert records in MemTab
MemTab_del delete records in MemTab
MemTab_mod modify records
MemTab_load returns datablock and its nr of records
MemTab_get retrieve (copy out) records
MemTab_clear reset (memTab->rNr = 0;)
MemTab_free free MemTab-structure.
MemTab_wrf write MemTab to file
MemTab_rdf read MemTab from file
MEMTAB__ get data-record from index INLINE
MEMTAB_DAT get data-record complete INLINE
MEMTAB_IND get index (pointer to next free = nr of used) INLINE
MEMTAB_RESET_IND reset index (nr of used = 0) INLINE
MEMTAB_RMAX get max. nr of records INLINE
MEMTAB_RSIZ get record size INLINE
MEMTAB_RFREE get nr of free records INLINE
MEMTAB_POS get position of next data-record INLINE
MEMTAB_IND_POS get record-index from position INLINE
MEMTAB_IS_EMPTY test if MemTab.data == NULL INLINE
MemTabI_add_s add n int's to int-table (add consecutive values)
List_functions_end:
=====================================================
- necessary includes:
#include "../ut/ut_memTab.h" // MemTab
- see also:
../doc/gCAD3D_prog_de.txt section Memoryfunktionen

Function Documentation

int MemTab_spc ( MemTab memTab,
void *  data,
int  dSiz,
int  rSiz,
int  typ 
)

MemTab_spc init memory-table with fixed memoryspace; no realloc, free

* INPUT:
* data memspc to connect
* dSiz size of data in bytes
* rSiz recordsize in bytes
* typ info; Typ_PT=Point Typ_Int4=int Typ_Float8=double Typ_Int1=char;
*
* Example get MemTab in tempSpace:
* int lNr=100; int mSizb; Line *lna; MemTab(Line) mln = _MEMTAB_NUL;
* mSizb = lNr * sizeof(Line); lna = (Line*) MEM_alloc_tmp (mSizb);
* MemTab_spc (&mln, lna, mSizb, sizeof(Line), Typ_LN);
*
int MemTab_ini ( void *  mtbv,
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 *  mtbv,
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
*
int MemTab_sav ( MemTab memTab,
long *  spcOff,
void *  objDat,
int  recNr 
)
int MemTab_uniq_sav ( MemTab memTab,
long *  spcOff,
void *  objDat 
)
* MemTab_uniq_add if data is uniq only: save data with MemTab_add (.. 1, 0);
* API see MemTab_add
* RetCode
* 2 objDat already exists
*
int MemTab_reserve ( MemTab memTab,
long *  spcOff,
int  recNr 
)
int MemTab_check ( MemTab memTab,
long *  spcOff,
int  recNr 
)
int MemTab_load ( void **  oTab,
int *  iNr,
MemTab mt 
)
* MemTab_load returns datablock and its nr of records
* use:
* MemTab_load ((void**)&oTab, &iNr, (MemTab*)&delTab);
* see also MemTab_get
*
int MemTab_get ( void *  objDat,
MemTab mt,
int  ipos,
int  recNr 
)
* MemTab_get retrieve (copy out) records
* get <recNr> records starting with record <ipos>
*
* Input:
* ipos 1. record to replace in mt->data
* recNr nr of records to overwrite
* Output:
* objDat data out of memSpc
* RetCodes:
* -1 not yet allocated (ipos+recNr > mt->rNr)
*
int MemTab_mod ( MemTab mt,
void *  objDat,
int  ipos,
int  recNr 
)
* MemTab_mod modify records
* modify <recNr> records starting with record <ipos>
*
* Input:
* objDat data to be saved in memSpc
* ipos 1. record to replace in mt->data
* recNr nr of records to overwrite
* RetCodes:
* -1 not yet allocated (ipos+recNr > mt->rNr)
*
int MemTab_del ( MemTab mt,
int  ipos,
int  delRecNr 
)
* MemTab_del delete records in MemTab
* delete <delRecNr> records starting with record <ipos>
* Input:
* ipos 1. record to delete in mt->data
* delRecNr nr of records to delete
* -1 delete all records following <ipos> and including <ipos>
*
int MemTab_ins ( MemTab mt,
long *  spcOff,
void *  objDat,
int  ipos,
int  insRecNr 
)
* MemTab_ins insert records in MemTab
* insert <insRecNr> records before record <ipos>
*
int MemTab_clear ( MemTab memTab)

MemTab_clear reset (memTab->rNr = 0;)

int MemTab_free ( MemTab memTab)

MemTab_free free MemTab-structure.

int MemTab_wrf ( FILE *  fp1,
MemTab mt 
)
int MemTab_rdf ( FILE *  fp1,
MemTab mt1 
)
int MemTab_dump ( MemTab memTab,
char *  info 
)