My Project  UNKNOWN_GIT_VERSION
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 
17 class omallocClass
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  void* addr;
47  if (size==(size_t)0) size = (size_t)1;
48  omTypeAlloc(void*, addr, size);
49  return addr;
50 }
51 
52 void operator delete[] ( void* block )
53 #ifndef __GNUC__
54 throw ()
55 #endif
56 {
57  omfree( block );
58 }
59 
60 
61 // The C++ standard has ratified a change to the new operator.
62 //
63 // T *p = new T;
64 //
65 // Previously, if the call to new above failed, a null pointer would've been returned.
66 // Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
67 // It is possible to suppress this behaviour in favour of the old style
68 // by using the nothrow version.
69 //
70 // T *p = new (std::nothrow) T;
71 //
72 // So we have to overload this new also, just to be sure.
73 //
74 // A further interesting question is, if you don't have enough resources
75 // to allocate a request for memory,
76 // do you expect to have enough to be able to deal with it?
77 // Most operating systems will have slowed to be unusable
78 // long before the exception gets thrown.
79 
80 void * operator new(size_t size, const std::nothrow_t &) throw();
81 
82 void * operator new[](size_t size, const std::nothrow_t &) throw();
83 };
84 #endif
85 #endif
omTypeAlloc
#define omTypeAlloc(type, addr, size)
Definition: omAllocDecl.h:206
omalloc.h
omFree
#define omFree(addr)
Definition: omAllocDecl.h:259
block
#define block
Definition: scanner.cc:664
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
omallocClass
Definition: omallocClass.h:16
omfree
#define omfree(addr)
Definition: omAllocDecl.h:235