|
1 /* Copyright (c) 2009 The Khronos Group Inc. |
|
2 * |
|
3 * Permission is hereby granted, free of charge, to any person obtaining a |
|
4 * copy of this software and/or associated documentation files (the |
|
5 * "Materials"), to deal in the Materials without restriction, including |
|
6 * without limitation the rights to use, copy, modify, merge, publish, |
|
7 * distribute, sublicense, and/or sell copies of the Materials, and to |
|
8 * permit persons to whom the Materials are furnished to do so, subject to |
|
9 * the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice shall be included |
|
12 * in all copies or substantial portions of the Materials. |
|
13 * |
|
14 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
20 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
21 */ |
|
22 #ifndef OWFMEMORY_H_ |
|
23 #define OWFMEMORY_H_ |
|
24 |
|
25 #include <stdlib.h> |
|
26 #include "owftypes.h" |
|
27 #include "owfdebug.h" |
|
28 |
|
29 #ifdef __cplusplus |
|
30 extern "C" |
|
31 { |
|
32 #endif |
|
33 |
|
34 |
|
35 #ifdef DEBUG |
|
36 |
|
37 /* |
|
38 * In debug builds we use our own memory management functions: |
|
39 */ |
|
40 /* multiplication yields negative if overflowed */ |
|
41 #define xalloc(n, c) (((OWFint)n*c < c) ? NULL : OWF_Memory_Alloc(__FILE__, __LINE__, (n)*(c))) |
|
42 #define xfree(p) OWF_Memory_Free(p) |
|
43 |
|
44 #else |
|
45 |
|
46 #define xalloc(n, c) calloc(n, c) |
|
47 #define xfree(p) free(p) |
|
48 |
|
49 #endif |
|
50 |
|
51 #define NEW0N(x, n) (x*) xalloc(sizeof(x), n) |
|
52 #define NEW0(x) NEW0N(x, 1) |
|
53 |
|
54 OWF_API_CALL void* |
|
55 OWF_Memory_Alloc(const char* file, OWFint line, OWFuint32 size); |
|
56 |
|
57 OWF_API_CALL void |
|
58 OWF_Memory_Free(void* ptr); |
|
59 |
|
60 OWF_API_CALL void |
|
61 OWF_Memory_BlockDump(); |
|
62 |
|
63 |
|
64 #ifdef __cplusplus |
|
65 } |
|
66 #endif |
|
67 |
|
68 |
|
69 #endif |