gCAD3D 2.35
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_cast.h"

Functions

int MemTab_spc (MemTab *memTab, void *data, int dSiz, int rSiz, int typ)
 
int MemTab_ini (MemTab *memTab, int rSiz, int typ, int incSiz)
 
int MemTab_add (MemTab *memTab, 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_write (FILE *fp1, MemTab *mt)
 
int MemTab_read (FILE *fp1, MemTab *mt)
 
int MemTab_dump (MemTab *memTab)
 

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_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_write write MemTab to file
MemTab_read 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_MAX get size INLINE
MEMTAB_POS get position of next data-record INLINE
MEMTAB_IND_POS get record-index from position INLINE
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:
dSiz size in bytes
rSiz recordsize in bytes
typ info; Typ_PT=Point Typ_Int4=int Typ_Float8=double Typ_Int1=char;
int MemTab_ini ( MemTab memTab,
int  rSiz,
int  typ,
int  incSiz 
)
MemTab_ini init memory-table
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)
int MemTab_add ( MemTab 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 additional 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)
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_write ( FILE *  fp1,
MemTab mt 
)
int MemTab_read ( FILE *  fp1,
MemTab mt 
)
int MemTab_dump ( MemTab memTab)