3
* Mesa 3-D graphics library
6
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
/* $XFree86: xc/extras/Mesa/src/mem.h,v 1.9 2003/01/12 03:55:44 tsi Exp $ */
32
/* Do not reference mtypes.h from this file.
38
#if defined(WIN32) && defined(_DEBUG)
40
#ifndef _CRTDBG_MAP_ALLOC
41
# define _CRTDBG_MAP_ALLOC 1
45
#define _mesa_malloc(n) _malloc_dbg( n, _NORMAL_BLOCK, __FILE__ , __LINE__ )
46
#define _mesa_calloc(n) _calloc_dbg( 1, n, _NORMAL_BLOCK, __FILE__ , __LINE__ )
47
#define _mesa_free(p) _free_dbg(p, _NORMAL_BLOCK )
49
extern void *_mesa_align_malloc_dbg(size_t bytes, unsigned long alignment, const char *_file, int _line );
50
extern void *_mesa_align_calloc_dbg(size_t bytes, unsigned long alignment, const char *_file, int _line );
51
extern void _mesa_align_free_dbg(void *ptr, const char *_file, int _line);
53
#define _mesa_align_malloc( s, a ) _mesa_align_malloc_dbg( s, a, __FILE__ , __LINE__ )
54
#define _mesa_align_calloc( s, a ) _mesa_align_calloc_dbg( s, a, __FILE__ , __LINE__ )
55
#define _mesa_align_free(p) _mesa_align_free_dbg(p, __FILE__ , __LINE__)
57
#else /* WIN32 && _DEBUG */
59
extern void *_mesa_malloc(size_t bytes);
60
extern void *_mesa_calloc(size_t bytes);
61
extern void _mesa_free(void *ptr);
63
extern void *_mesa_align_malloc(size_t bytes, unsigned long alignment);
64
extern void *_mesa_align_calloc(size_t bytes, unsigned long alignment);
65
extern void _mesa_align_free(void *ptr);
67
#endif /* WIN32 && _DEBUG */
72
/* call Mesa memory functions */
73
#define MALLOC(BYTES) _mesa_malloc(BYTES)
74
#define CALLOC(BYTES) _mesa_calloc(BYTES)
75
#define MALLOC_STRUCT(T) (struct T *) _mesa_malloc(sizeof(struct T))
76
#define CALLOC_STRUCT(T) (struct T *) _mesa_calloc(sizeof(struct T))
77
#define FREE(PTR) _mesa_free(PTR)
81
/* directly call C lib memory functions */
82
#define MALLOC(BYTES) (void *) malloc(BYTES)
83
#define CALLOC(BYTES) (void *) calloc(1, BYTES)
84
#define MALLOC_STRUCT(T) (struct T *) malloc(sizeof(struct T))
85
#define CALLOC_STRUCT(T) (struct T *) calloc(1,sizeof(struct T))
86
#define FREE(PTR) free(PTR)
90
/* call Mesa N-byte aligned memory functions */
91
#define ALIGN_MALLOC(BYTES, N) (void *) _mesa_align_malloc(BYTES, N)
92
#define ALIGN_CALLOC(BYTES, N) (void *) _mesa_align_calloc(BYTES, N)
93
#define ALIGN_MALLOC_STRUCT(T, N) (struct T *) _mesa_align_malloc(sizeof(struct T), N)
94
#define ALIGN_CALLOC_STRUCT(T, N) (struct T *) _mesa_align_calloc(sizeof(struct T), N)
95
#define ALIGN_FREE(PTR) _mesa_align_free(PTR)
98
#ifdef MESA_EXTERNAL_BUFFERALLOC
100
* If you want Mesa's depth/stencil/accum/etc buffers to be allocated
101
* with a specialized allocator you can define MESA_EXTERNAL_BUFFERALLOC
102
* and implement _ext_mesa_alloc/free_pixelbuffer() in your app.
103
* Contributed by Gerk Huisma (gerk@five-d.demon.nl).
105
extern void *_ext_mesa_alloc_pixelbuffer( unsigned int size );
106
extern void _ext_mesa_free_pixelbuffer( void *pb );
108
#define MESA_PBUFFER_ALLOC(BYTES) (void *) _ext_mesa_alloc_pixelbuffer(BYTES)
109
#define MESA_PBUFFER_FREE(PTR) _ext_mesa_free_pixelbuffer(PTR)
111
/* Default buffer allocation uses the aligned allocation routines: */
112
#define MESA_PBUFFER_ALLOC(BYTES) (void *) _mesa_align_malloc(BYTES, 512)
113
#define MESA_PBUFFER_FREE(PTR) _mesa_align_free(PTR)
119
#define MEMCPY( DST, SRC, BYTES) \
120
memcpy( (char *) (DST), (char *) (SRC), (int) (BYTES) )
122
#define MEMCPY( DST, SRC, BYTES) \
123
memcpy( (void *) (DST), (void *) (SRC), (size_t) (BYTES) )
129
#define MEMSET( DST, VAL, N ) \
130
memset( (char *) (DST), (int) (VAL), (int) (N) )
132
#define MEMSET( DST, VAL, N ) \
133
memset( (void *) (DST), (int) (VAL), (size_t) (N) )
136
extern void _mesa_memset16( GLushort *dst, GLushort val, size_t n );
138
#define MEMSET16( DST, VAL, N ) \
139
_mesa_memset16( (GLushort *) (DST), (GLushort) (VAL), (size_t) (N) )
142
/* On some systems we might want to use bzero() (but is bzero portable?) */
143
#if defined(__FreeBSD__)
144
#define BZERO( ADDR, N ) \
145
bzero( (void *) (ADDR), (size_t) (N) )
147
#define BZERO( ADDR, N ) \
148
memset( (void *) (ADDR), 0, (size_t) (N) )
152
/* MACs and BeOS don't support static larger than 32kb, so... */
153
#if defined(macintosh) && !defined(__MRC__)
154
/*extern char *AGLAlloc(int size);*/
155
/*extern void AGLFree(char* ptr);*/
156
# define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)MALLOC(sizeof(TYPE)*(SIZE))
157
# define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])MALLOC(sizeof(TYPE)*(SIZE1)*(SIZE2))
158
# define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])MALLOC(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
160
# define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
161
# define UNDEFARRAY(NAME) do {if ((NAME)) {FREE((char*)NAME);} }while (0)
162
#elif defined(__BEOS__)
163
# define DEFARRAY(TYPE,NAME,SIZE) TYPE *NAME = (TYPE*)malloc(sizeof(TYPE)*(SIZE))
164
# define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE (*NAME)[SIZE2] = (TYPE(*)[SIZE2])malloc(sizeof(TYPE)*(SIZE1)*(SIZE2))
165
# define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE (*NAME)[SIZE2][SIZE3] = (TYPE(*)[SIZE2][SIZE3])malloc(sizeof(TYPE)*(SIZE1)*(SIZE2)*(SIZE3))
166
# define CHECKARRAY(NAME,CMD) do {if (!(NAME)) {CMD;}} while (0)
167
# define UNDEFARRAY(NAME) do {if ((NAME)) {free((char*)NAME);} }while (0)
169
# define DEFARRAY(TYPE,NAME,SIZE) TYPE NAME[SIZE]
170
# define DEFMARRAY(TYPE,NAME,SIZE1,SIZE2) TYPE NAME[SIZE1][SIZE2]
171
# define DEFMNARRAY(TYPE,NAME,SIZE1,SIZE2,SIZE3) TYPE NAME[SIZE1][SIZE2][SIZE3]
172
# define CHECKARRAY(NAME,CMD) do {} while(0)
173
# define UNDEFARRAY(NAME)