[5f8b5e] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[64673d] | 4 | /* $Id: mmalloc.cc,v 1.7 2008-10-28 09:12:40 Singular Exp $ */ |
---|
[5f8b5e] | 5 | /* |
---|
| 6 | * ABSTRACT: standard version of C++-memory management alloc func |
---|
| 7 | */ |
---|
| 8 | #include <stdlib.h> |
---|
| 9 | |
---|
| 10 | #include "mod2.h" |
---|
| 11 | |
---|
| 12 | #include <omalloc.h> |
---|
[ad83e4] | 13 | #include <new> |
---|
[5f8b5e] | 14 | |
---|
| 15 | /* We define those, so that our values of |
---|
| 16 | OM_TRACK and OM_CHECK are used */ |
---|
| 17 | void* operator new ( size_t size ) |
---|
| 18 | { |
---|
| 19 | void* addr; |
---|
[64673d] | 20 | if (size==(size_t)0) size = 1; |
---|
[5f8b5e] | 21 | omTypeAlloc(void*, addr, size); |
---|
| 22 | return addr; |
---|
| 23 | } |
---|
| 24 | |
---|
[64673d] | 25 | void operator delete ( void* block ) |
---|
| 26 | { |
---|
| 27 | omfree( block ); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | void* operator new[] ( size_t size ) |
---|
| 31 | { |
---|
| 32 | void* addr; |
---|
| 33 | if (size==(size_t)0) size = (size_t)1; |
---|
| 34 | omTypeAlloc(void*, addr, size); |
---|
| 35 | return addr; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | void operator delete[] ( void* block ) |
---|
| 39 | { |
---|
| 40 | omfree( block ); |
---|
| 41 | } |
---|
| 42 | |
---|
[ad83e4] | 43 | // The C++ standard has ratified a change to the new operator. |
---|
| 44 | // |
---|
| 45 | // T *p = new T; |
---|
| 46 | // |
---|
| 47 | // Previously, if the call to new above failed, a null pointer would've been returned. |
---|
| 48 | // Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown. |
---|
| 49 | // It is possible to suppress this behaviour in favour of the old style |
---|
| 50 | // by using the nothrow version. |
---|
| 51 | // |
---|
| 52 | // T *p = new (std::nothrow) T; |
---|
| 53 | // |
---|
| 54 | // So we have to overload this new also, just to be sure. |
---|
| 55 | // |
---|
| 56 | // A further interesting question is, if you don't have enough resources |
---|
| 57 | // to allocate a request for memory, |
---|
| 58 | // do you expect to have enough to be able to deal with it? |
---|
| 59 | // Most operating systems will have slowed to be unusable |
---|
| 60 | // long before the exception gets thrown. |
---|
| 61 | |
---|
| 62 | void * operator new(size_t size, const std::nothrow_t &) throw() |
---|
| 63 | { |
---|
| 64 | void* addr; |
---|
| 65 | if (size==(size_t)0) size = (size_t)1; |
---|
| 66 | omTypeAlloc(void*, addr, size); |
---|
| 67 | return addr; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void * operator new[](size_t size, const std::nothrow_t &) throw() |
---|
| 71 | { |
---|
| 72 | void* addr; |
---|
| 73 | if (size==(size_t)0) size = (size_t)1; |
---|
| 74 | omTypeAlloc(void*, addr, size); |
---|
| 75 | return addr; |
---|
| 76 | } |
---|