source: git/omalloc/omallocClass.cc @ 0338ae9

spielwiese
Last change on this file since 0338ae9 was e03d7b, checked in by Hans Schoenemann <hannes@…>, 9 years ago
opt: omallocClass mostly inlined
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: standard version of C++-memory management alloc func
6*/
7
8#include <omalloc/omalloc.h>
9
10#ifdef __cplusplus
11
12#include <new>
13#include <stdlib.h>
14#include <omalloc/omallocClass.h>
15
16void*  omallocClass::operator new[] ( size_t size )
17#ifndef __GNUC__
18throw (std::bad_alloc)
19#endif
20{
21  void* addr;
22  if (size==(size_t)0) size = (size_t)1;
23  omTypeAlloc(void*, addr, size);
24  return addr;
25}
26
27void  omallocClass::operator delete[] ( void* block )
28#ifndef __GNUC__
29throw ()
30#endif
31{
32  omfree( block );
33}
34
35// The C++ standard has ratified a change to the new operator.
36//
37//  T *p = new T;
38//
39// Previously, if the call to new above failed, a null pointer would've been returned.
40// Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
41// It is possible to suppress this behaviour in favour of the old style
42// by using the nothrow version.
43//
44//  T *p = new (std::nothrow) T;
45//
46// So we have to overload this new also, just to be sure.
47//
48// A further interesting question is, if you don't have enough resources
49// to allocate a request for memory,
50// do you expect to have enough to be able to deal with it?
51// Most operating systems will have slowed to be unusable
52// long before the exception gets thrown.
53
54void *  omallocClass::operator new(size_t size, const std::nothrow_t &) throw()
55{
56  void* addr;
57  omTypeAlloc(void*, addr, size);
58  return addr;
59}
60
61void *  omallocClass::operator new[](size_t size, const std::nothrow_t &) throw()
62{
63  void* addr;
64  if (size==(size_t)0) size = (size_t)1;
65  omTypeAlloc(void*, addr, size);
66  return addr;
67}
68#endif
Note: See TracBrowser for help on using the repository browser.