1 | /* -*- C++ -*- */ |
---|
2 | |
---|
3 | /* |
---|
4 | |
---|
5 | Heap Layers: An Extensible Memory Allocation Infrastructure |
---|
6 | |
---|
7 | Copyright (C) 2000-2005 by Emery Berger |
---|
8 | http://www.cs.umass.edu/~emery |
---|
9 | emery@cs.umass.edu |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify |
---|
12 | it under the terms of the GNU General Public License as published by |
---|
13 | the Free Software Foundation; either version 2 of the License, or |
---|
14 | (at your option) any later version. |
---|
15 | |
---|
16 | This program is distributed in the hope that it will be useful, |
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | GNU General Public License for more details. |
---|
20 | |
---|
21 | You should have received a copy of the GNU General Public License |
---|
22 | along with this program; if not, write to the Free Software |
---|
23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
24 | |
---|
25 | */ |
---|
26 | |
---|
27 | #ifndef _MALLOCHEAP_H_ |
---|
28 | #define _MALLOCHEAP_H_ |
---|
29 | |
---|
30 | #include <stdlib.h> |
---|
31 | |
---|
32 | #if defined(__SVR4) |
---|
33 | extern "C" size_t malloc_usable_size (void *); |
---|
34 | #else |
---|
35 | extern "C" size_t malloc_usable_size (void *) throw (); |
---|
36 | #endif |
---|
37 | |
---|
38 | #if defined(_WIN32) || defined(linux) |
---|
39 | #include <malloc.h> |
---|
40 | #elif defined(__APPLE__) |
---|
41 | #include <malloc/malloc.h> |
---|
42 | #endif |
---|
43 | |
---|
44 | /** |
---|
45 | * @class mallocHeap |
---|
46 | * @brief A "source heap" that uses malloc and free. |
---|
47 | */ |
---|
48 | |
---|
49 | namespace HL { |
---|
50 | |
---|
51 | class mallocHeap { |
---|
52 | public: |
---|
53 | |
---|
54 | ~mallocHeap (void) {} |
---|
55 | |
---|
56 | inline void * malloc (size_t sz) { |
---|
57 | return ::malloc (sz); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | inline void free (void * ptr) { |
---|
62 | ::free (ptr); |
---|
63 | } |
---|
64 | |
---|
65 | #if defined(_MSC_VER) |
---|
66 | inline size_t getSize (void * ptr) { |
---|
67 | return ::_msize (ptr); |
---|
68 | } |
---|
69 | #elif defined(__GNUC__) && !defined(__SVR4) |
---|
70 | inline size_t getSize (void * ptr) { |
---|
71 | return ::malloc_usable_size (ptr); |
---|
72 | } |
---|
73 | #elif defined(__APPLE__) |
---|
74 | inline size_t getSize (void * ptr) { |
---|
75 | return ::malloc_size (ptr); |
---|
76 | } |
---|
77 | #endif |
---|
78 | |
---|
79 | }; |
---|
80 | |
---|
81 | }; |
---|
82 | |
---|
83 | #endif |
---|