source: git/omalloc/omallocClass.h @ dc50ee

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