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