source: git/kernel/mmalloc.cc @ b938f4

spielwiese
Last change on this file since b938f4 was 5f4463, checked in by Hans Schoenemann <hannes@…>, 13 years ago
making the sun-c/c++ compiler happy (still waiting for to issues...) git-svn-id: file:///usr/local/Singular/svn/trunk@14137 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5/*
6* ABSTRACT: standard version of C++-memory management alloc func
7*/
8#include <stdlib.h>
9
10#include <kernel/mod2.h>
11
12#include <omalloc/omalloc.h>
13#include <new>
14
15/* We define those, so that our values of
16   OM_TRACK and OM_CHECK are used  */
17void* operator new ( size_t size )
18#ifndef __GNUC__
19throw (std::bad_alloc)
20#endif
21{
22  void* addr;
23  if (size==(size_t)0) size = 1;
24  omTypeAlloc(void*, addr, size);
25  return addr;
26}
27
28void operator delete ( void* block )
29#ifndef __GNUC__
30throw ()
31#endif
32{
33  omfree( block );
34}
35
36void* operator new[] ( size_t size )
37#ifndef __GNUC__
38throw (std::bad_alloc)
39#endif
40{
41  void* addr;
42  if (size==(size_t)0) size = (size_t)1;
43  omTypeAlloc(void*, addr, size);
44  return addr;
45}
46
47void operator delete[] ( void* block )
48#ifndef __GNUC__
49throw ()
50#endif
51{
52  omfree( block );
53}
54
55// The C++ standard has ratified a change to the new operator.
56//
57//  T *p = new T;
58//
59// Previously, if the call to new above failed, a null pointer would've been returned.
60// Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
61// It is possible to suppress this behaviour in favour of the old style
62// by using the nothrow version.
63//
64//  T *p = new (std::nothrow) T;
65//
66// So we have to overload this new also, just to be sure.
67//
68// A further interesting question is, if you don't have enough resources
69// to allocate a request for memory,
70// do you expect to have enough to be able to deal with it?
71// Most operating systems will have slowed to be unusable
72// long before the exception gets thrown.
73
74void * operator new(size_t size, const std::nothrow_t &) throw()
75{
76  void* addr;
77  if (size==(size_t)0) size = (size_t)1;
78  omTypeAlloc(void*, addr, size);
79  return addr;
80}
81
82void * operator new[](size_t size, const std::nothrow_t &) throw()
83{
84  void* addr;
85  if (size==(size_t)0) size = (size_t)1;
86  omTypeAlloc(void*, addr, size);
87  return addr;
88}
Note: See TracBrowser for help on using the repository browser.