Eneboo - Documentación para desarrolladores
|
00001 // -*- C++ -*- 00002 00003 /* 00004 00005 Heap Layers: An Extensible Memory Allocation Infrastructure 00006 00007 Copyright (C) 2000-2003 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 _EXCEPTION_HEAP 00028 #define _EXCEPTION_HEAP 00029 00030 #include <new> 00031 #include <new.h> 00032 00033 class std::bad_alloc; 00034 00035 namespace HL { 00036 00037 template <class Super> 00038 class ExceptionHeap : public Super { 00039 public: 00040 inline void * malloc (size_t sz) throw (std::bad_alloc) { 00041 void * ptr = Super::malloc (sz); 00042 if (ptr == NULL) { 00043 throw new std::bad_alloc; 00044 } 00045 return ptr; 00046 } 00047 }; 00048 00049 00050 template <class Super> 00051 class CatchExceptionHeap : public Super { 00052 public: 00053 inline void * malloc (size_t sz) { 00054 void * ptr; 00055 try { 00056 ptr = Super::malloc (sz); 00057 } catch (std::bad_alloc) { 00058 ptr = NULL; 00059 } 00060 return ptr; 00061 } 00062 }; 00063 00064 }; 00065 00066 #endif