Newer
Older
1
2
3
4
5
6
7
8
9
10
11
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
#ifndef _SHMEM_H
#define _SHMEM_H
#ifdef __cplusplus
extern "C" {
#endif
#if CAVEMENU
# define CAVE 1
#endif
#if CAVE
/* Shared memory definitions */
#include <malloc.h> /* for amalloc() */
#define NewN(type, count) (type *)shmalloc((count) * sizeof(type))
#define RenewN(p,type,count) (type *)shmrealloc(p, (count) * sizeof(type))
#define Free(p) shmfree( p )
extern void *aarena;
extern void shminit( int bytes );
extern void shmusearena( void *arena );
extern void *shmalloc(int nbytes);
extern void shmfree(void *ptr);
extern void *shmrealloc(void *ptr, int nbytes);
extern char *shmstrdup(char *str);
/* If we run out of memory, ask (*func)(data, nbytes, arena)
* to free some.
* func should return 1 if it freed something (i.e. if it's
* worth retrying the allocation), 0 if no improvement.
* We should really have a list of these functions,
* for multiple separately-written clients of our shmem pool.
*/
extern void shmrecycler( int (*func)(void *, int, void *), void *data );
#else /* non-CAVE */
#define NewN(type, count) ((type *)malloc((count) * sizeof(type)))
#define RenewN(p,type,count) ((type *)realloc(p, (count) * sizeof(type)))
#define Free(p) free( p )
#define shmstrdup(str) strdup(str)
#endif /*!CAVEMENU*/
#define OOGLNewNE(type, count, str) NewN(type, count)
#define OOGLReNewNE(p,type,count,str) RenewN(p,type,count)
#define OOGLFree(p) Free(p)
#ifdef __cplusplus
}
#endif
#endif