source: git/Singular/mmalloc.cc @ f5d2647

spielwiese
Last change on this file since f5d2647 was ba5e9e, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Changed configure-scripts to generate individual public config files for each package: resources, libpolys, singular (main) fix: sources should include correct corresponding config headers.
  • 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#ifdef HAVE_CONFIG_H
10#include "singularconfig.h"
11#endif /* HAVE_CONFIG_H */
12#include <kernel/mod2.h>
13
14#include <omalloc/omalloc.h>
15#include <new>
16
17/* We define those, so that our values of
18   OM_TRACK and OM_CHECK are used  */
19void* operator new ( size_t size )
20#ifndef __GNUC__
21throw (std::bad_alloc)
22#endif
23{
24  void* addr;
25  if (size==(size_t)0) size = 1;
26  omTypeAlloc(void*, addr, size);
27  return addr;
28}
29
30void operator delete ( void* block )
31#ifndef __GNUC__
32throw ()
33#endif
34{
35  omfree( block );
36}
37
38void* operator new[] ( size_t size )
39#ifndef __GNUC__
40throw (std::bad_alloc)
41#endif
42{
43  void* addr;
44  if (size==(size_t)0) size = (size_t)1;
45  omTypeAlloc(void*, addr, size);
46  return addr;
47}
48
49void operator delete[] ( void* block )
50#ifndef __GNUC__
51throw ()
52#endif
53{
54  omfree( block );
55}
56
57// The C++ standard has ratified a change to the new operator.
58//
59//  T *p = new T;
60//
61// Previously, if the call to new above failed, a null pointer would've been returned.
62// Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
63// It is possible to suppress this behaviour in favour of the old style
64// by using the nothrow version.
65//
66//  T *p = new (std::nothrow) T;
67//
68// So we have to overload this new also, just to be sure.
69//
70// A further interesting question is, if you don't have enough resources
71// to allocate a request for memory,
72// do you expect to have enough to be able to deal with it?
73// Most operating systems will have slowed to be unusable
74// long before the exception gets thrown.
75
76void * operator new(size_t size, const std::nothrow_t &) throw()
77{
78  void* addr;
79  if (size==(size_t)0) size = (size_t)1;
80  omTypeAlloc(void*, addr, size);
81  return addr;
82}
83
84void * operator new[](size_t size, const std::nothrow_t &) throw()
85{
86  void* addr;
87  if (size==(size_t)0) size = (size_t)1;
88  omTypeAlloc(void*, addr, size);
89  return addr;
90}
Note: See TracBrowser for help on using the repository browser.