00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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