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