MALOC  0.1
vset.h
Go to the documentation of this file.
1 
38 #ifndef _VSET_H_
39 #define _VSET_H_
40 
41 #include <maloc/maloc_base.h>
42 
43 #include <maloc/vnm.h>
44 #include <maloc/vmem.h>
45 
46 /*
47  * ***************************************************************************
48  * Class Vset: Parameters and datatypes
49  * ***************************************************************************
50  */
51 
57 struct sVset {
58 
62  int iMadeVmem;
63 
65  int curT;
66 
70  int sizeT;
71 
73  int numBlocks;
75  int numT;
77  int prtT;
78 
80  int maxObjects;
82  int blockPower;
84  int blockSize;
86  int blockMax;
89 
91  char **table;
92 
93 };
94 
100 typedef struct sVset Vset;
101 
102 /****************************************************************/
103 /* Class Vset: Inlineable method (vset.c) */
104 /****************************************************************/
105 
106 #if !defined(VINLINE_MALOC)
115  int Vset_num(Vset *thee);
116 
126  char *Vset_access(Vset *thee, int i);
127 
136  char *Vset_create(Vset *thee);
137 
146  char *Vset_first(Vset *thee);
147 
156  char *Vset_last(Vset *thee);
157 
166  char *Vset_next(Vset *thee);
167 
176  char *Vset_prev(Vset *thee);
177 
186  char *Vset_peekFirst(Vset *thee);
187 
196  char *Vset_peekLast(Vset *thee);
197 
206  void Vset_destroy(Vset *thee);
207 #else /* if defined(VINLINE_MALOC) */
216 # define Vset_num(thee) ((thee)->numT)
217 
227 # define Vset_access(thee,i) ( \
228  ((i >= 0) && (i < thee->numT)) \
229  ? &((thee)->table[ (i)>>(thee)->blockPower ] \
230  [ (thee)->sizeT*((i)&(thee)->blockModulo) ]) \
231  : VNULL \
232  )
233 
242 # define Vset_create(thee) ( \
243  ( ((((thee)->numT)>>(thee)->blockPower) >= (thee)->numBlocks) \
244  || ((((thee)->numT+1)%(thee)->prtT) == 0) ) \
245  ? (Vset_createLast((thee))) \
246  : (++((thee)->numT), (Vset_access((thee),(thee)->numT-1))) \
247  )
248 
257 # define Vset_first(thee) ( \
258  (thee)->curT = 0, \
259  Vset_access((thee), (thee)->curT) \
260  )
261 
270 # define Vset_last(thee) ( \
271  (thee)->curT = (thee)->numT-1, \
272  Vset_access((thee), (thee)->curT) \
273  )
274 
283 # define Vset_next(thee) ( \
284  (thee)->curT++, \
285  ((thee)->curT < (thee)->numT) \
286  ? Vset_access((thee), (thee)->curT) \
287  : VNULL \
288  )
289 
298 # define Vset_prev(thee) ( \
299  (thee)->curT--, \
300  ((thee)->curT >= 0) \
301  ? Vset_access((thee), (thee)->curT) \
302  : VNULL \
303  )
304 
313 # define Vset_peekFirst(thee) ( \
314  Vset_access((thee), 0) \
315  )
316 
325 # define Vset_peekLast(thee) ( \
326  Vset_access((thee), (thee)->numT-1) \
327  )
328 
337 # define Vset_destroy(thee) ( \
338  ( ((((thee)->numT-1)>>(thee)->blockPower) < (thee)->numBlocks-1) \
339  || ((thee)->numT == 1) || ((((thee)->numT)%(thee)->prtT) == 0) ) \
340  ? (Vset_destroyLast((thee))) : (void)(((thee)->numT)--) \
341  )
342 #endif /* if !defined(VINLINE_MALOC) */
343 
357  const char *tname, int tsize, int tmaxNum, int ioKey);
358 
367 void Vset_dtor(Vset **thee);
368 
377 char *Vset_createLast(Vset *thee);
378 
387 void Vset_destroyLast(Vset *thee);
388 
397 void Vset_initData(Vset *thee);
398 
407 void Vset_reset(Vset *thee);
408 
422 void Vset_check(Vset *thee,
423  int *tnum, int *tsize, int *tVecUse, int *tVecMal, int *tVecOhd);
424 
433 void Vset_memChk(Vset *thee);
434 
435 #endif /* _VSET_H_ */
436 
The base (or foundation) header for MALOC.
#define VMAX_ARGLEN
Global constant.
Definition: maloc_base.h:227
Class Vmem: A safer, object-oriented, malloc/free object.
Header file for an ISO C [V]irtual [N]umerical [M]achine.
Vset * Vset_ctor(Vmem *vmem, const char *tname, int tsize, int tmaxNum, int ioKey)
Construct the set object.
char * Vset_first(Vset *thee)
Return the first object in the set.
char * Vset_peekLast(Vset *thee)
Return the last object in the set.
char * Vset_last(Vset *thee)
Return the last object in the set.
void Vset_dtor(Vset **thee)
Destroy the set object.
char * Vset_peekFirst(Vset *thee)
Return the first object in the set.
char * Vset_next(Vset *thee)
Return the next object in the set.
void Vset_reset(Vset *thee)
Release all Ram controlled by this (thee) and re-initialize.
char * Vset_createLast(Vset *thee)
Create an object on the end of the list.
void Vset_initData(Vset *thee)
Initialize the Vset data (thee).
void Vset_destroyLast(Vset *thee)
Free up the object currently on the end of the list.
void Vset_memChk(Vset *thee)
Print the exact current malloc usage.
void Vset_check(Vset *thee, int *tnum, int *tsize, int *tVecUse, int *tVecMal, int *tVecOhd)
Get and return the RAM Control Block (thee) information.
char * Vset_prev(Vset *thee)
Return the prev object in the set.
int Vset_num(Vset *thee)
Return the number of things currently in the list.
char * Vset_access(Vset *thee, int i)
Access an object in an arbitrary place in the list.
void Vset_destroy(Vset *thee)
Delete an object from the end of the list.
char * Vset_create(Vset *thee)
Create an object on the end of the list.
Contains public data members for Vmem class.
Definition: vmem.h:57
Contains public data members for Vset class.
Definition: vset.h:57
int blockModulo
=blockSize-1; for determining which block fast
Definition: vset.h:88
char nameT[VMAX_ARGLEN]
name of object we are managing
Definition: vset.h:68
int iMadeVmem
did i make vmem or was it inherited
Definition: vset.h:62
int blockSize
blocksize is 2^(blockPower)
Definition: vset.h:84
char ** table
list of pointers to blocks of storage we manage
Definition: vset.h:91
int numBlocks
total number of allocated blocks
Definition: vset.h:73
int prtT
for i/o at appropriate block creation/deletion
Definition: vset.h:77
Vmem * vmem
the memory manager
Definition: vset.h:60
int curT
the current "T" object in our collection
Definition: vset.h:65
int blockMax
num blocks = blockMax=(maxObjects/blockSize)
Definition: vset.h:86
int sizeT
size of the object in bytes
Definition: vset.h:70
int blockPower
power of 2 for blocksize (e.g., =10, or =16)
Definition: vset.h:82
int maxObjects
number of objects to manage (user specified)
Definition: vset.h:80
int numT
the global "T" counter – how many "T"s in list
Definition: vset.h:75