gCAD3D 2.35
ut_umem.h File Reference

Go to the source code of this file.

Data Structures

struct  Memspc
 Typ_Memspc (a class for variable-length-records in memory) More...
 
struct  MemObj
 
union  memobj_union
 

Macros

#define UME_NEW   {NULL, NULL, NULL, 0}
 init Memspc More...
 
#define UME_alloc_tmp(memSeg, memsiz)   UME_init (memSeg, MEM_alloc_tmp(memsiz), memsiz)
 
#define UME_get_next(memSeg)   ((memSeg)->next)
 UME_get_next get actual memSpacePosition (.next; next free position) More...
 
#define UME_set_next(memPos, memSeg)   (memSeg)->next=memPos
 
#define UME_get_start(memSeg)   (memSeg)->start
 
#define UME_get_used(memSeg)   ((char*)(memSeg)->next - (char*)(memSeg)->start)
 UME_get_used get used space. More...
 
#define UME_connect(memPos, memSeg)   (memPos)=(memSeg)->next
 
#define PTR_MEMOBJ(MO)   ((memobj_union*)&MO)->vp
 
#define MEMOBJ_PTR(p)   ((memobj_union*)p)->mo
 
#define UME_obj_IS_VALID(mo1)   (int)((mo1)->ioff - 4)
 

Functions

int UME_init (Memspc *memSpc, void *objDat, int osiz)
 
int UME_alloc_tmp (Memspc *memSpc, long spcSiz)
 
int UME_malloc (Memspc *memSpc, long spcSiz, long memInc)
 
void * UME_save (Memspc *memSpc, void *objDat, int osiz)
 
void * UME_reserve (Memspc *memSpc, int osiz)
 
int UME_add (Memspc *memSpc, int osiz)
 
int UME_adjust (Memspc *memSpc, void *newStart)
 
int UME_ck_free (Memspc *memSpc)
 
int UME_set_free (int sizFree, Memspc *memSpc)
 
int UME_dump (Memspc *memSpc, char *txt)
 
int UME_del (Memspc *memSpc, void *nach, void *von,...)
 
void UME_connect (void *memPos, Memspc *memSeg)
 
int UME_reall_add (long *spcOff, Memspc *memSpc, long addSiz)
 
int UME_realloc (long *spcOff, Memspc *memSpc, long newSiz)
 
int UME_reall_save (long *spcOff, Memspc *memSpc, void *objDat, int osiz)
 
void * UME_get_next (Memspc *memSpc)
 
void * UME_get_start (Memspc *memSpc)
 
long UME_get_used (Memspc *memSpc)
 
MemObj UME_obj_reserve (void **oPos, Memspc *mSpc, int siz, int mbId)
 
int UME_obj_save (int mbId, Memspc *mSpc, int recNr)
 
void * UME_obj_get (MemObj *mo)
 
MemObj UME_obj_invalid_set (int iErr)
 

Macro Definition Documentation

#define UME_NEW   {NULL, NULL, NULL, 0}

init Memspc

#define UME_alloc_tmp (   memSeg,
  memsiz 
)    UME_init (memSeg, MEM_alloc_tmp(memsiz), memsiz)
#define UME_get_next (   memSeg)    ((memSeg)->next)

UME_get_next get actual memSpacePosition (.next; next free position)

#define UME_set_next (   memPos,
  memSeg 
)    (memSeg)->next=memPos

UME_set_next set actual memSpacePosition (.next; next free position) reset after UME_get_next (regain memspace)

#define UME_get_start (   memSeg)    (memSeg)->start

UME_get_start get startPosition of Memspc returns start position in Memspc (spc.start; first obj)

#define UME_get_used (   memSeg)    ((char*)(memSeg)->next - (char*)(memSeg)->start)

UME_get_used get used space.

#define UME_connect (   memPos,
  memSeg 
)    (memPos)=(memSeg)->next

UME_connect DO NOT USE get actual memSpacePosition use UME_get_next Output: memPos next free position in memSeg (as void*)

#define PTR_MEMOBJ (   MO)    ((memobj_union*)&MO)->vp
#define MEMOBJ_PTR (   p)    ((memobj_union*)p)->mo
#define UME_obj_IS_VALID (   mo1)    (int)((mo1)->ioff - 4)

test if object is valid; >=0 is OK; else invalid object. MemObj *mo; if(UME_obj_IS_VALID(mo) < 0) ERROR

Function Documentation

int UME_init ( Memspc memSpc,
void *  objDat,
int  osiz 
)
UME_init init Memspc
puts memSpc as first Record into objDat; gives back its Adress.
Examples:
char memspc51[50000];
Memspc memSeg1;
int *iTab, sizTab;
// attach memspc51
UME_init (&memSeg1, memspc51, sizeof(memspc51));
// give whole space to iTab; do not fix memspc.next
UME_connect (iTab, &memSeg1);
// set max size for iTab
sizTab = UME_ck_free (&memSeg1) / sizeof(int);
// reserve 100 int's in memSeg1; update memspc.next.
iTab = UME_reserve (&memSeg1, 100 * sizeof(int));
// give the remaining space to (char*)cbuf
UME_connect (cbuf, memSeg1);
// query size of cbuf
cbufSiz = UME_ck_free (memSeg1);
see also ../doc/gCAD3D_prog_de.txt section Memoryfunktionen
int UME_alloc_tmp ( Memspc ,
long   
)
UME_alloc_tmp allocate temp. space for Memspc
DO NOT GET > 100000 byte
memspace exists until active function returns (using alloca)
MUST BE INLINE; after return of function memspace is lost !
Example:
Memspc tmpSpc=UME_NEW;
UME_alloc_tmp (&tmpSpc, 1000); // get a Memspc size = 1000 bytes
int UME_malloc ( Memspc memSpc,
long  spcSiz,
long  memInc 
)
malloc <spcSiz> bytes and provide it in memSpc.
Call UME_malloc only once!
Memspace must be freed with UME_free
Input:
spcSiz malloc this size
memInc if reallocate: increase <memInc> bytes
Output:
RetCode 0=OK; -1=outOfMemory-Error.
Example:
Memspc tmpSpc=UME_UME_NEW;
UME_malloc (&tmpSpc, 100 *sizeof(int), 50 *sizeof(int));
...
UME_free (&tmpSpc);
void* UME_save ( Memspc memSpc,
void *  objDat,
int  osiz 
)
UME_save save Obj -> Memspc
RetCode: the address (starting-Position) of the memSpace;
NULL if EOM
void* UME_reserve ( Memspc memSpc,
int  osiz 
)
UME_reserve get memSpacePos & reserve space
RetCode: the address (starting-Position) of the memSpace;
NULL if EOM (not enough memspace)
int UME_add ( Memspc memSpc,
int  osiz 
)
DO NOT USE (use UME_reserve)
UME_add den next-Pointer korrigieren (Obj. manuell speichern)
RetCod 0=OK, -1=OutOfSpace
Platz reservieren; wird nachfolgend NICHT mit UME_save belegt.
Achtung Reihenfolge:
1) den Pointer merken
Point *pTab;
pTab = UME_get_next (&memSeg1); // pTab = (Point*)memSeg1.next;
2) den Platz reservieren (aendert den Pointer memSeg1->next)
i1 = UME_add (&memSeg1, sizeof(Point) * ptNr);
if(i1 < 0) goto L_eom; // Test ob genug Platz im memSeg
3) den Platz belegen
memcpy (pTab, pta, sizeof(Point) * ptNr);
int UME_adjust ( Memspc memSpc,
void *  newStart 
)
int UME_ck_free ( Memspc memSpc)

UME_ck_free return free space

int UME_set_free ( int  sizFree,
Memspc memSpc 
)
UME_set_free correct free space (release n bytes)
usage:
UME_set_free (sSiz, wrkSpc); // release sSiz bytes)
sSiz >0 cut off <sSiz> from end of data
-1 clear whole data
int UME_dump ( Memspc memSpc,
char *  txt 
)

UME_dump display free space

int UME_del ( Memspc memSpc,
void *  nach,
void *  von,
  ... 
)
Datenbereich (u Pointer) loeschen (nach links verschieben);
"nach" muss also kleiner als "von" sein !!
void UME_connect ( void *  memPos,
Memspc memSeg 
)
int UME_reall_add ( long *  spcOff,
Memspc memSpc,
long  addSiz 
)
add = allocate Space for <addSiz> bytes; reallocate if necessary.
next-Pointer is incremented <addSiz> bytes
Input:
addSiz occupy <addSiz> bytes in memSpc
0: must increase memSpc
Output:
spcOff displacement-offset; 0: no reallocate.
RetCode 0=OK; -1=outOfMemory-Error.
int UME_realloc ( long *  spcOff,
Memspc memSpc,
long  newSiz 
)
memspc vergroessern; die Pointer start, next und end korrigieren.
Input:
newSiz is new total size of memSpc
Output:
spcOff distance from active memSpc->start to new memSpc->start
int UME_reall_save ( long *  spcOff,
Memspc memSpc,
void *  objDat,
int  osiz 
)
UME_reall_save save Obj -> Memspc
next-Pointer is incremented <addSiz> bytes and
<osiz> bytes from position <objDat> are saved into memSpc.
Input:
oSiz nr of bytes to save
objDat date to be saved in memSpc
Output:
spcOff displacement-offset; 0: no reallocate.
RetCode 0=OK; -1=outOfMemory-Error.
void* UME_get_next ( Memspc memSpc)
void* UME_get_start ( Memspc memSpc)
long UME_get_used ( Memspc memSpc)
MemObj UME_obj_reserve ( void **  oPos,
Memspc mSpc,
int  siz,
int  mbId 
)
int UME_obj_save ( int  mbId,
Memspc mSpc,
int  recNr 
)

save Memspc -> memoryblock (malloc & memcpy)

void* UME_obj_get ( MemObj mo)
get object-position from MemObj
MemObj contains memblock-nr and the data-offset in this memoryblock.
MemObj UME_obj_invalid_set ( int  iErr)
Set MemObj to Error.
iErr must be 0-3
-4 0 uninitialized or deleted;
-3 1 error with parent-object
-2 2 application-error
-1 3 out-of-space-error