gCAD3D 2.35
ut_umem.c File Reference

variable-length-records in memory: reserve/connect/release .. UME_ More...

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "../ut/ut_cast.h"
#include "../ut/ut_umem.h"
#include "../ut/ut_umb.h"
#include "../ut/ut_TX.h"

Functions

int UME_write__ (char *fnam, Memspc *memSpc)
 
int UME_read__ (Memspc *memSpc, char *fnam)
 
int UME_realloc (long *spcOff, Memspc *memSpc, long newSiz)
 
int UME_malloc (Memspc *memSpc, long spcSiz, long memInc)
 
int UME_free (Memspc *memSpc)
 
int UME_init (Memspc *memSpc, void *objDat, int osiz)
 
int UME_adjust (Memspc *memSpc, void *nxtFree)
 
void * UME_reserve (Memspc *memSpc, int osiz)
 
int UME_add (Memspc *memSpc, int osiz)
 
int UME_reall_add (long *spcOff, Memspc *memSpc, long addSiz)
 
int UME_reall_save (long *spcOff, Memspc *memSpc, void *objDat, int osiz)
 
void * UME_save (Memspc *memSpc, void *objDat, int osiz)
 
int UME_ck_free (Memspc *memSpc)
 
int UME_ck_tot (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,...)
 
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)
 
void UME_obj_dump (MemObj *mo)
 

Detailed Description

variable-length-records in memory: reserve/connect/release .. UME_

=====================================================
List_functions_start:
UME_init init Memspc with existing space
UME_malloc init Memspc, malloc
UME_alloc_tmp allocate temp. space (until functions ends) INLINE
UME_save save Obj -> Memspc
UME_reall_save save and reallocate if necessary
UME_reall_add add and reallocate if necessary
UME_del remove space (toPos - fromPos)
UME_reserve get memSpacePos & reserve space
UME_adjust set memSpacePos (reserve space; set .next)
UME_set_free correct free space (release n bytes)
UME_get_next get actual memSpacePosition INLINE
UME_get_start get startPosition of Memspc (NULL = uninitialized) INLINE
UME_get_used get used space INLINE
UME_ck_free return free space
UME_ck_tot report total space
UME_dump display free space
MEM_alloc_tmp allocate mem for active function (temp.space)
UME_TMP_FILE allocate temp.memspace for file INLINE
UME_obj_reserve reserve space in Memspc and return a MemObj
UME_obj_get get object-position from MemObj
UME_write__ write memSpc into file
UME_read__ read file into Memspc
UME_connect DO NOT USE (use UME_get_next) INLINE
UME_add DO NOT USE (use UME_reserve)
UME_NEW setup. unused
List_functions_end:
=====================================================
- see also:
../doc/gCAD3D_prog_de.txt section Memoryfunktionen

Function Documentation

int UME_write__ ( char *  fnam,
Memspc memSpc 
)

write memSpc into file

int UME_read__ ( Memspc memSpc,
char *  fnam 
)
read file into Memspc;
Memspc must have enough free space;
RetCod: 0=OK; -1=memSpc_too_small; -2=file_error;
Example:
l1 = OS_FilSiz (fnam);
UME_alloc_tmp (&tmpSpc1, l1);
UME_read__ (&tmpSpc1, fnam);
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_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);
int UME_free ( Memspc memSpc)
das komplette memseg mit free im OS freigeben !
auch:
free (memSpc->start);
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_adjust ( Memspc memSpc,
void *  nxtFree 
)
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_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_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_save ( Memspc memSpc,
void *  objDat,
int  osiz 
)
UME_save save Obj -> Memspc
RetCode: the address (starting-Position) of the memSpace;
NULL if EOM
int UME_ck_free ( Memspc memSpc)

UME_ck_free return free space

int UME_ck_tot ( Memspc memSpc)

UME_ck_tot report total 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 !!
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
void UME_obj_dump ( MemObj mo)