source: vis_dev/glu-2.1/src/mem/memint.h @ 13

Last change on this file since 13 was 8, checked in by cecile, 13 years ago

src glu

File size: 3.1 KB
RevLine 
[8]1/* Memory management internal definitions */
2
3
4#if !defined(_MEMINTH)
5#define _MEMINTH
6
7
8/* All user-visible stuff */
9
10#include "memuser.h"
11
12
13/* >>> Potentially system dependent configuration stuff */
14/* See memuser.h as well. */
15
16/* The storage management library can either use system-provided */
17/* versions of malloc, free and friends, or it can implement a buddy */
18/* scheme based on something like sbrk.  If you want to do the former, */
19/* define USE_MALLOC_FREE. */
20
21/* #define USE_MALLOC_FREE */
22
23/* Now we need macros for routines to copy and zero-fill blocks of */
24/* memory, and to either do malloc/free/whatever or to do an sbrk.  Since */
25/* different systems have different types that these routines expect, we */
26/* wrap everything in macros. */
27
28#if defined(USE_MALLOC_FREE)
29#if defined(__STDC__)
30extern void *malloc(unsigned long);
31extern void free(void *);
32extern void *realloc(void *, unsigned long);
33#define MALLOC(size) ((pointer)malloc((unsigned long)(size)))
34#define FREE(p) (free((void *)(p)))
35#define REALLOC(p, size) ((pointer)realloc((void *)(p), (unsigned long)(size)))
36#else
37extern char *malloc();
38extern void free();
39extern char *realloc();
40#define MALLOC(size) ((pointer)malloc((int)(size)))
41#define FREE(p) (free((char *)(p)))
42#define REALLOC(p, size) ((pointer)realloc((char *)(p), (int)(size)))
43#endif
44#else
45#if defined(__STDC__)
46#ifdef HAVE_UNISTD_H
47#include <unistd.h>
48#else
49extern char *sbrk(int);
50#endif
51#define SBRK(size) ((pointer)sbrk((int)(size)))
52#else
53extern char *sbrk();
54#define SBRK(size) ((pointer)sbrk((int)(size)))
55#endif
56#endif
57
58/* You may need to muck with these depending on whether you have */
59/* bcopy or memcpy. */
60
61#if defined(__STDC__)
62#if STDC_HEADERS
63#include <string.h>
64#else
65extern void *memcpy(); /* TRS, 6/17/94: removed arg types to suppress warning on mips/gcc */
66/* extern void *memcpy(void *, const void *, unsigned long); */
67
68extern void *memset(); /* SPK 3/01/01: removed arg types to suppress
69                          warning on linux-rh-6.2/egcs-2.91/66 */
70/* extern void *memset(void *, int, unsigned long); */
71#endif
72#define MEM_COPY(dest, src, size) (void)memcpy((void *)(dest), (const void *)(src), (unsigned long)(size))
73#define MEM_ZERO(ptr, size) (void)memset((void *)(ptr), 0, (unsigned long)(size))
74#else
75extern void bcopy();
76extern void bzero();
77#define MEM_COPY(dest, src, size) bcopy((char *)(src), (char *)(dest), (int)(size))
78#define MEM_ZERO(ptr, size) bzero((char *)(ptr), (int)(size))
79#endif
80
81
82#if defined(__STDC__)
83#define ARGS(args) args
84#else
85#define ARGS(args) ()
86#endif
87
88
89/* >>> System independent stuff here. */
90
91struct segment_
92{
93  pointer base_address;
94  SIZE_T limit;
95};
96
97typedef struct segment_ *segment;
98
99
100struct block_
101{
102  int used;
103  int size_index;
104  struct block_ *next;
105  struct block_ *prev;
106  segment seg;
107};
108
109typedef struct block_ *block;
110
111
112#define HEADER_SIZE ((SIZE_T)ROUNDUP(sizeof(struct block_)))
113#define MAX_SIZE_INDEX (8*sizeof(SIZE_T)-2)
114#define MAX_SEG_SIZE ((SIZE_T)1 << MAX_SIZE_INDEX)
115#define MAX_SIZE ((SIZE_T)(MAX_SEG_SIZE-HEADER_SIZE))
116#define MIN_ALLOC_SIZE_INDEX 15
117
118#define NICE_BLOCK_SIZE ((SIZE_T)4096-ROUNDUP(sizeof(struct block_)))
119
120
121extern void mem_fatal ARGS((char *));
122
123
124#undef ARGS
125
126#endif
Note: See TracBrowser for help on using the repository browser.