source: git/kernel/mmalloc.cc @ eab144e

spielwiese
Last change on this file since eab144e was 64673d, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: re-ordered git-svn-id: file:///usr/local/Singular/svn/trunk@11162 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: mmalloc.cc,v 1.7 2008-10-28 09:12:40 Singular Exp $ */
5/*
6* ABSTRACT: standard version of C++-memory management alloc func
7*/
8#include <stdlib.h>
9
10#include "mod2.h"
11
12#include <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{
19  void* addr;
20  if (size==(size_t)0) size = 1;
21  omTypeAlloc(void*, addr, size);
22  return addr;
23}
24
25void operator delete ( void* block )
26{
27  omfree( block );
28}
29
30void* operator new[] ( size_t size )
31{
32  void* addr;
33  if (size==(size_t)0) size = (size_t)1;
34  omTypeAlloc(void*, addr, size);
35  return addr;
36}
37
38void operator delete[] ( void* block )
39{
40  omfree( block );
41}
42
43// The C++ standard has ratified a change to the new operator.
44//
45//  T *p = new T;
46//
47// Previously, if the call to new above failed, a null pointer would've been returned.
48// Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
49// It is possible to suppress this behaviour in favour of the old style
50// by using the nothrow version.
51//
52//  T *p = new (std::nothrow) T;
53//
54// So we have to overload this new also, just to be sure.
55//
56// A further interesting question is, if you don't have enough resources
57// to allocate a request for memory,
58// do you expect to have enough to be able to deal with it?
59// Most operating systems will have slowed to be unusable
60// long before the exception gets thrown.
61
62void * operator new(size_t size, const std::nothrow_t &) throw()
63{
64  void* addr;
65  if (size==(size_t)0) size = (size_t)1;
66  omTypeAlloc(void*, addr, size);
67  return addr;
68}
69
70void * operator new[](size_t size, const std::nothrow_t &) throw()
71{
72  void* addr;
73  if (size==(size_t)0) size = (size_t)1;
74  omTypeAlloc(void*, addr, size);
75  return addr;
76}
Note: See TracBrowser for help on using the repository browser.