Newer
Older
#ifndef CAT_MODELUTIL_H
#define CAT_MODELUTIL_H
/*
* Utility functions for cat_model.
*
* Stuart Levy, slevy@ncsa.uiuc.edu
* National Center for Supercomputing Applications,
* University of Illinois 2001.
* This file is part of partiview, released under the
* Illinois Open Source License; see the file LICENSE.partiview for details.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "shmem.h"
class Shmem {
/* Shared-memory allocator.
*/
public:
void *operator new( size_t s ) { totalloc += s; return NewN( char, s ); }
// void *operator new[]( size_t s );
void operator delete( void *p ) { Free(p); }
// void operator delete[]( void *p );
/* Copy a string to shared memory */
static char *strdup( char *str ) { return shmstrdup(str); }
static void *salloc( size_t s ) { totalloc += s; return NewN( char, s ); }
static void sfree( void *p ) { Free(p); }
static int totalloc;
};
/* Extendable array of vect's, stored in CAVEMalloc'ed memory.
* Should be a template.
*/
template <class T>
class vvec : public Shmem {
public:
int count; /* Number of items defined in *v */
int room; /* Total space available in *v */
int ours; /* "May we sfree(v)?" */
T *v; /* Data */
vvec();
~vvec();
void init();
vvec( int space ); /* initial estimate */
void init( int space ); /* ditto */
void use( T *buf, int space ); /* "Use this buffer" */
void trim( int excess = 0 ); /* trim to size, and ensure CAVEMalloc()ed */
T *needs( int nitems );
T *append(); /* Extend by 1, and return address of new item */
T *val( int index ); /* index'th item (extending if needed) */
};
#endif /*CAT_MODELUTIL_H*/