source: git/omalloc/omallocClass.cc @ 8450df

fieker-DuValspielwiese
Last change on this file since 8450df was 3e056d, checked in by Hans Schoenemann <hannes@…>, 8 years ago
xalloc: how to use and fixes
  • 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
14// The C++ standard has ratified a change to the new operator.
15//
16//  T *p = new T;
17//
18// Previously, if the call to new above failed, a null pointer would've been returned.
19// Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
20// It is possible to suppress this behaviour in favour of the old style
21// by using the nothrow version.
22//
23//  T *p = new (std::nothrow) T;
24//
25// So we have to overload this new also, just to be sure.
26//
27// A further interesting question is, if you don't have enough resources
28// to allocate a request for memory,
29// do you expect to have enough to be able to deal with it?
30// Most operating systems will have slowed to be unusable
31// long before the exception gets thrown.
32
33void *  omallocClass::operator new(size_t size, const std::nothrow_t &) throw()
34{
35  void* addr;
36  omTypeAlloc(void*, addr, size);
37  return addr;
38}
39
40void *  omallocClass::operator new[](size_t size, const std::nothrow_t &) throw()
41{
42  void* addr;
43  if (size==(size_t)0) size = (size_t)1;
44  omTypeAlloc(void*, addr, size);
45  return addr;
46}
47#endif
Note: See TracBrowser for help on using the repository browser.