source: git/factory/newdelete.cc @ fbb0173

spielwiese
Last change on this file since fbb0173 was 650f2d8, checked in by Mohamed Barakat <mohamed.barakat@…>, 13 years ago
renamed assert.h -> cf_assert.h in factory
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id$ */
3
4#include <config.h>
5#include <new>
6
7#include "cf_assert.h"
8
9#ifdef USE_OLD_MEMMAN
10#include "memutil.h"
11#else
12#include "memman.h"
13#endif
14
15// The C++ standard has ratified a change to the new operator.
16//
17//  T *p = new T;
18//
19// Previously, if the call to new above failed, a null pointer would've been returned.
20// Under the ISO C++ Standard, an exception of type std::bad_alloc is thrown.
21// It is possible to suppress this behaviour in favour of the old style
22// by using the nothrow version.
23//
24//  T *p = new (std::nothrow) T;
25//
26// So we have to overload this new also, just to be sure.
27//
28// A further interesting question is, if you don't have enough resources
29// to allocate a request for memory,
30// do you expect to have enough to be able to deal with it?
31// Most operating systems will have slowed to be unusable
32// long before the exception gets thrown.
33
34#ifdef USE_OLD_MEMMAN
35
36void * operator new ( size_t size )
37{
38    return getBlock( size );
39}
40
41void operator delete ( void * block )
42{
43    freeBlock( block, 0 );
44}
45
46void * operator new[] ( size_t size )
47{
48    return getBlock( size );
49}
50
51void operator delete[] ( void * block )
52{
53    freeBlock( block, 0 );
54}
55
56void * operator new(size_t size, std::nothrow_t) throw()
57{
58    return getBlock( size );
59}
60void * operator new[](size_t size, std::nothrow_t) throw()
61{
62    return getBlock( size );
63}
64
65#else
66
67void * operator new ( size_t size )
68{
69    return mmAlloc( size );
70}
71
72void operator delete ( void * block )
73{
74    mmFree( block );
75}
76
77void * operator new[] ( size_t size )
78{
79    return mmAlloc( size );
80}
81
82void operator delete[] ( void * block )
83{
84    mmFree( block );
85}
86
87void * operator new(size_t size, const std::nothrow_t&) throw()
88{
89    return mmAlloc( size );
90}
91void * operator new[](size_t size, const std::nothrow_t&) throw()
92{
93    return mmAlloc( size );
94}
95
96#endif /* USE_OLD_MEMMAN */
Note: See TracBrowser for help on using the repository browser.