source: git/kernel/mmalloc.cc @ abe5c8

fieker-DuValspielwiese
Last change on this file since abe5c8 was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • 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 <stdlib.h>
8
9#include "config.h"
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.