source: git/omalloc/omallocClass.cc @ 886fb4

fieker-DuValspielwiese
Last change on this file since 886fb4 was db143c, checked in by Hans Schoenemann <hannes@…>, 5 years ago
integrate xalloc into omalloc (./configure --disable-omalloc)
  • Property mode set to 100644
File size: 1.3 KB
Line 
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
32void *  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
39void *  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
Note: See TracBrowser for help on using the repository browser.