Eneboo - Documentación para desarrolladores
|
00001 /* -*- C++ -*- */ 00002 00003 /* 00004 00005 Heap Layers: An Extensible Memory Allocation Infrastructure 00006 00007 Copyright (C) 2000-2005 by Emery Berger 00008 http://www.cs.umass.edu/~emery 00009 emery@cs.umass.edu 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; either version 2 of the License, or 00014 (at your option) any later version. 00015 00016 This program is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with this program; if not, write to the Free Software 00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 00025 */ 00026 00027 #ifndef _MALLOCHEAP_H_ 00028 #define _MALLOCHEAP_H_ 00029 00030 #include <cstdlib> 00031 00032 #if defined(__SVR4) 00033 extern "C" size_t malloc_usable_size (void *); 00034 #else 00035 extern "C" size_t malloc_usable_size (void *) throw (); 00036 #endif 00037 00038 #if defined(_WIN32) || defined(linux) 00039 #include <malloc.h> 00040 #elif defined(__APPLE__) 00041 #include <malloc/malloc.h> 00042 #endif 00043 00049 namespace HL { 00050 00051 class mallocHeap { 00052 public: 00053 00054 ~mallocHeap (void) {} 00055 00056 inline void * malloc (size_t sz) { 00057 return ::malloc (sz); 00058 } 00059 00060 00061 inline void free (void * ptr) { 00062 ::free (ptr); 00063 } 00064 00065 #if defined(_MSC_VER) 00066 inline size_t getSize (void * ptr) { 00067 return ::_msize (ptr); 00068 } 00069 #elif defined(__GNUC__) && !defined(__SVR4) 00070 inline size_t getSize (void * ptr) { 00071 return ::malloc_usable_size (ptr); 00072 } 00073 #elif defined(__APPLE__) 00074 inline size_t getSize (void * ptr) { 00075 return ::malloc_size (ptr); 00076 } 00077 #endif 00078 00079 }; 00080 00081 }; 00082 00083 #endif