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
60 Vmem *vmem;
62 int iMadeVmem;
63
65 int curT;
66
68 char nameT[VMAX_ARGLEN];
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;
88 int blockModulo;
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
356 Vset* Vset_ctor(Vmem *vmem,
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
maloc_base.h
The base (or foundation) header for MALOC.
VMAX_ARGLEN
#define VMAX_ARGLEN
Global constant.
Definition maloc_base.h:227
vnm.h
Header file for an ISO C [V]irtual [N]umerical [M]achine.
vmem.h
Class Vmem: A safer, object-oriented, malloc/free object.
Vset_peekFirst
char * Vset_peekFirst(Vset *thee)
Return the first object in the set.
Vset_prev
char * Vset_prev(Vset *thee)
Return the prev object in the set.
Vset_dtor
void Vset_dtor(Vset **thee)
Destroy the set object.
Vset_first
char * Vset_first(Vset *thee)
Return the first object in the set.
Vset_ctor
Vset * Vset_ctor(Vmem *vmem, const char *tname, int tsize, int tmaxNum, int ioKey)
Construct the set object.
Vset_reset
void Vset_reset(Vset *thee)
Release all Ram controlled by this (thee) and re-initialize.
Vset_next
char * Vset_next(Vset *thee)
Return the next object in the set.
Vset_initData
void Vset_initData(Vset *thee)
Initialize the Vset data (thee).
Vset_destroyLast
void Vset_destroyLast(Vset *thee)
Free up the object currently on the end of the list.
Vset_create
char * Vset_create(Vset *thee)
Create an object on the end of the list.
Vset_memChk
void Vset_memChk(Vset *thee)
Print the exact current malloc usage.
Vset_check
void Vset_check(Vset *thee, int *tnum, int *tsize, int *tVecUse, int *tVecMal, int *tVecOhd)
Get and return the RAM Control Block (thee) information.
Vset_num
int Vset_num(Vset *thee)
Return the number of things currently in the list.
Vset_peekLast
char * Vset_peekLast(Vset *thee)
Return the last object in the set.
Vset_last
char * Vset_last(Vset *thee)
Return the last object in the set.
Vset_destroy
void Vset_destroy(Vset *thee)
Delete an object from the end of the list.
Vset_createLast
char * Vset_createLast(Vset *thee)
Create an object on the end of the list.
Vset_access
char * Vset_access(Vset *thee, int i)
Access an object in an arbitrary place in the list.
sVmem
Contains public data members for Vmem class.
Definition vmem.h:57
sVset
Contains public data members for Vset class.
Definition vset.h:57
sVset::blockModulo
int blockModulo
=blockSize-1; for determining which block fast
Definition vset.h:88
sVset::nameT
char nameT[VMAX_ARGLEN]
name of object we are managing
Definition vset.h:68
sVset::iMadeVmem
int iMadeVmem
did i make vmem or was it inherited
Definition vset.h:62
sVset::blockSize
int blockSize
blocksize is 2^(blockPower)
Definition vset.h:84
sVset::table
char ** table
list of pointers to blocks of storage we manage
Definition vset.h:91
sVset::numBlocks
int numBlocks
total number of allocated blocks
Definition vset.h:73
sVset::prtT
int prtT
for i/o at appropriate block creation/deletion
Definition vset.h:77
sVset::vmem
Vmem * vmem
the memory manager
Definition vset.h:60
sVset::curT
int curT
the current "T" object in our collection
Definition vset.h:65
sVset::blockMax
int blockMax
num blocks = blockMax=(maxObjects/blockSize)
Definition vset.h:86
sVset::sizeT
int sizeT
size of the object in bytes
Definition vset.h:70
sVset::blockPower
int blockPower
power of 2 for blocksize (e.g., =10, or =16)
Definition vset.h:82
sVset::maxObjects
int maxObjects
number of objects to manage (user specified)
Definition vset.h:80
sVset::numT
int numT
the global "T" counter – how many "T"s in list
Definition vset.h:75