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