Changeset ad83e4 in git
- Timestamp:
- Oct 25, 2008, 1:05:51 PM (15 years ago)
- Branches:
- (u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
- Children:
- 3fe8ed4d13cc002b2f0fb89d6eeacd9ee3f7a568
- Parents:
- b0e3efca092d580bdd55fac90beff461dacda552
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/newdelete.cc
rb0e3efc rad83e4 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: newdelete.cc,v 1. 2 1997-06-19 12:22:03 schmidtExp $ */2 /* $Id: newdelete.cc,v 1.3 2008-10-25 11:04:06 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 11 11 #include "memman.h" 12 12 #endif 13 14 // The C++ standard has ratified a change to the new operator. 15 // 16 // T *p = new T; 17 // 18 // Previously, if the call to new above failed, a null pointer would've been returned. 19 // Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown. 20 // It is possible to suppress this behaviour in favour of the old style 21 // by using the nothrow version. 22 // 23 // T *p = new (std::nothrow) T; 24 // 25 // So we have to overload this new also, just to be sure. 26 // 27 // A further interesting question is, if you don't have enough resources 28 // to allocate a request for memory, 29 // do you expect to have enough to be able to deal with it? 30 // Most operating systems will have slowed to be unusable 31 // long before the exception gets thrown. 13 32 14 33 #ifdef USE_OLD_MEMMAN … … 32 51 { 33 52 freeBlock( block, 0 ); 53 } 54 55 void * operator new(size_t size, const std::nothrow_t &) throw() 56 { 57 return getBlock( size ); 58 } 59 void * operator new[](size_t size, const std::nothrow_t &) throw() 60 { 61 return getBlock( size ); 34 62 } 35 63 … … 56 84 } 57 85 86 void * operator new(size_t size, const std::nothrow_t &) throw() 87 { 88 return mmAlloc( size ); 89 } 90 void * operator new[](size_t size, const std::nothrow_t &) throw() 91 { 92 return mmAlloc( size ); 93 } 94 58 95 #endif /* USE_OLD_MEMMAN */ -
kernel/mmalloc.cc
rb0e3efc rad83e4 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mmalloc.cc,v 1. 5 2006-07-27 09:09:37Singular Exp $ */4 /* $Id: mmalloc.cc,v 1.6 2008-10-25 11:05:51 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: standard version of C++-memory management alloc func … … 11 11 12 12 #include <omalloc.h> 13 #include <new> 13 14 14 15 /* We define those, so that our values of … … 18 19 void* addr; 19 20 if (!size) size = 1; 21 omTypeAlloc(void*, addr, size); 22 return addr; 23 } 24 25 // The C++ standard has ratified a change to the new operator. 26 // 27 // T *p = new T; 28 // 29 // Previously, if the call to new above failed, a null pointer would've been returned. 30 // Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown. 31 // It is possible to suppress this behaviour in favour of the old style 32 // by using the nothrow version. 33 // 34 // T *p = new (std::nothrow) T; 35 // 36 // So we have to overload this new also, just to be sure. 37 // 38 // A further interesting question is, if you don't have enough resources 39 // to allocate a request for memory, 40 // do you expect to have enough to be able to deal with it? 41 // Most operating systems will have slowed to be unusable 42 // long before the exception gets thrown. 43 44 void * operator new(size_t size, const std::nothrow_t &) throw() 45 { 46 void* addr; 47 if (size==(size_t)0) size = (size_t)1; 20 48 omTypeAlloc(void*, addr, size); 21 49 return addr; … … 30 58 { 31 59 void* addr; 32 if ( ! size) size =1;60 if (size==(size_t)0) size = (size_t)1; 33 61 omTypeAlloc(void*, addr, size); 34 62 return addr; 35 63 } 64 65 void * operator new[](size_t size, const std::nothrow_t &) throw() 66 { 67 void* addr; 68 if (size==(size_t)0) size = (size_t)1; 69 omTypeAlloc(void*, addr, size); 70 return addr; 71 } 72 36 73 37 74 void operator delete[] ( void* block )
Note: See TracChangeset
for help on using the changeset viewer.