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