1 | /* $Id: mem.h,v 1.1 2000-05-23 20:34:53 jeroen Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Mesa 3-D graphics library
|
---|
5 | * Version: 3.3
|
---|
6 | *
|
---|
7 | * Copyright (C) 1999 Brian Paul All Rights Reserved.
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
10 | * copy of this software and associated documentation files (the "Software"),
|
---|
11 | * to deal in the Software without restriction, including without limitation
|
---|
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
13 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
14 | * Software is furnished to do so, subject to the following conditions:
|
---|
15 | *
|
---|
16 | * The above copyright notice and this permission notice shall be included
|
---|
17 | * in all copies or substantial portions of the Software.
|
---|
18 | *
|
---|
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
---|
20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
---|
23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
---|
24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | #ifndef MEM_H
|
---|
29 | #define MEM_H
|
---|
30 |
|
---|
31 |
|
---|
32 | #include "glheader.h"
|
---|
33 |
|
---|
34 |
|
---|
35 | /*
|
---|
36 | * Memory allocation
|
---|
37 | */
|
---|
38 | #ifdef DEBUG
|
---|
39 |
|
---|
40 | /* call Mesa memory functions */
|
---|
41 | extern void *_mesa_malloc(size_t bytes);
|
---|
42 | extern void *_mesa_calloc(size_t bytes);
|
---|
43 | extern void _mesa_free(void *ptr);
|
---|
44 | #define MALLOC(BYTES) _mesa_malloc(BYTES)
|
---|
45 | #define CALLOC(BYTES) _mesa_calloc(BYTES)
|
---|
46 | #define MALLOC_STRUCT(T) (struct T *) _mesa_malloc(sizeof(struct T))
|
---|
47 | #define CALLOC_STRUCT(T) (struct T *) _mesa_calloc(sizeof(struct T))
|
---|
48 | #define FREE(PTR) _mesa_free(PTR)
|
---|
49 |
|
---|
50 | #else
|
---|
51 |
|
---|
52 | /* directly call C lib memory functions */
|
---|
53 | #define MALLOC(BYTES) (void *) malloc(BYTES)
|
---|
54 | #define CALLOC(BYTES) (void *) calloc(1, BYTES)
|
---|
55 | #define MALLOC_STRUCT(T) (struct T *) malloc(sizeof(struct T))
|
---|
56 | #define CALLOC_STRUCT(T) (struct T *) calloc(1,sizeof(struct T))
|
---|
57 | #define FREE(PTR) free(PTR)
|
---|
58 |
|
---|
59 | #endif
|
---|
60 |
|
---|
61 |
|
---|
62 | /* Memory copy: */
|
---|
63 | #ifdef SUNOS4
|
---|
64 | #define MEMCPY( DST, SRC, BYTES) \
|
---|
65 | memcpy( (char *) (DST), (char *) (SRC), (int) (BYTES) )
|
---|
66 | #else
|
---|
67 | #define MEMCPY( DST, SRC, BYTES) \
|
---|
68 | memcpy( (void *) (DST), (void *) (SRC), (size_t) (BYTES) )
|
---|
69 | #endif
|
---|
70 |
|
---|
71 |
|
---|
72 | /* Memory set: */
|
---|
73 | #ifdef SUNOS4
|
---|
74 | #define MEMSET( DST, VAL, N ) \
|
---|
75 | memset( (char *) (DST), (int) (VAL), (int) (N) )
|
---|
76 | #else
|
---|
77 | #define MEMSET( DST, VAL, N ) \
|
---|
78 | memset( (void *) (DST), (int) (VAL), (size_t) (N) )
|
---|
79 | #endif
|
---|
80 |
|
---|
81 |
|
---|
82 |
|
---|
83 | /* MACs and BeOS don't support static larger than 32kb, so... */
|
---|
84 | #if defined(macintosh) && !defined(__MRC__)
|
---|
85 | extern char *AGLAlloc(int size);
|
---|
86 | extern void AGLFree(char* ptr);
|
---|
87 | # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)AGLAlloc(sizeof(TYPE)*(SIZE))
|
---|
88 | # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])AGLAlloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
|
---|
89 | # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
|
---|
90 | # define UNDEFARRAY(NAME) do {if ((NAME)) {AGLFree((char*)NAME);} }while (0)
|
---|
91 | #elif defined(__BEOS__)
|
---|
92 | # define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)malloc(sizeof(TYPE)*(SIZE))
|
---|
93 | # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])malloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
|
---|
94 | # define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
|
---|
95 | # define UNDEFARRAY(NAME) do {if ((NAME)) {free((char*)NAME);} }while (0)
|
---|
96 | #else
|
---|
97 | # define DEFARRAY(TYPE,NAME,SIZE) TYPE NAME[SIZE]
|
---|
98 | # define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE NAME[SIZE1][SIZE2]
|
---|
99 | # define CHECKARRAY(NAME,CMD) do {} while(0)
|
---|
100 | # define UNDEFARRAY(NAME)
|
---|
101 | #endif
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 |
|
---|
106 | #endif
|
---|