My Project
omallocClass.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: standard version of C++-memory management alloc func
6 */
7 
8 #ifdef __cplusplus
9 
10 #include <new>
11 #include <stdlib.h>
12 #include "omalloc/omallocClass.h"
13 // The C++ standard has ratified a change to the new operator.
14 //
15 // T *p = new T;
16 //
17 // Previously, if the call to new above failed, a null pointer would've been returned.
18 // Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
19 // It is possible to suppress this behaviour in favour of the old style
20 // by using the nothrow version.
21 //
22 // T *p = new (std::nothrow) T;
23 //
24 // So we have to overload this new also, just to be sure.
25 //
26 // A further interesting question is, if you don't have enough resources
27 // to allocate a request for memory,
28 // do you expect to have enough to be able to deal with it?
29 // Most operating systems will have slowed to be unusable
30 // long before the exception gets thrown.
31 
32 void * omallocClass::operator new(size_t size, const std::nothrow_t &) throw()
33 {
34  void* addr;
35  omTypeAlloc(void*, addr, size);
36  return addr;
37 }
38 
39 void * omallocClass::operator new[](size_t size, const std::nothrow_t &) throw()
40 {
41  void* addr;
42  if (size==(size_t)0) size = (size_t)1;
43  omTypeAlloc(void*, addr, size);
44  return addr;
45 }
46 #endif
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