source: git/Singular/mmalloc.cc @ 72a01e

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