Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
etc
config
src
GLOBAL_BAD_ALLOC.cpp
Go to the documentation of this file.
1
// checking for class ::bad_alloc
2
3
25
#include "config.h"
26
#include "
nodbg.h
"
27
28
#if !defined (_RWSTD_NO_NEW_THROWS) && !defined (_RWSTD_NO_NEW_OFLOW_SAFE)
29
# include <
stddef.h
>
// for size_t
30
#endif
// !_RWSTD_NO_NEW_THROWS && !_RWSTD_NO_NEW_OFLOW_SAFE
31
32
#ifndef _RWSTD_NO_SETRLIMIT
33
// test for setrlimit() presence before compiling current file
34
#endif
35
36
// proclimits.h must be included only after #if[n]def _RWSTD_NO_SETRLIMIT
37
#include "
proclimits.h
"
38
39
#ifndef _RWSTD_NO_HONOR_STD
40
# ifdef _RWSTD_NO_STD_TERMINATE
41
# include "
terminate.h
"
42
# endif
// _RWSTD_NO_STD_TERMINATE
43
#endif
// _RWSTD_NO_HONOR_STD
44
45
46
struct
bad_alloc
{ };
47
48
49
int
main
()
50
{
51
// prevent MSVC's libc from popping up a dialog box
52
// with an out-of-memory message
53
nodbg
();
54
55
try
{
56
57
#ifndef _RWSTD_NO_NEW_THROWS
58
# ifndef _RWSTD_NO_NEW_OFLOW_SAFE
59
60
void
*
p
= ::operator
new
(size_t (-1));
61
62
if
(!
p
)
63
return
1;
64
65
# else
// if defined (_RWSTD_NO_NEW_OFLOW_SAFE)
66
67
limit_memory
(0);
68
69
for
(
unsigned
long
n
= 1UL << (
sizeof
(
long
) * 8 - 1);
70
0 !=
n
;
n
|= (
n
>> 1)) {
71
72
// try to allocate a huge amount of memory
73
void
*
p
= ::operator
new
(
n
);
74
75
if
(!
p
)
76
return
1;
77
}
78
79
# endif
// _RWSTD_NO_NEW_OFLOW_SAFE
80
#else
// if defined (_RWSTD_NO_NEW_THROWS)
81
82
return
4;
83
84
#endif
85
86
}
87
catch
(
bad_alloc
&) {
88
return
0;
89
}
90
catch
(...) {
91
return
2;
92
}
93
94
return
3;
95
}
n
#define n
Definition
17.names.cpp:130
p
#define p
Definition
17.names.cpp:132
main
int main()
Definition
GLOBAL_BAD_ALLOC.cpp:49
nodbg.h
nodbg
void nodbg()
Definition
nodbg.h:52
proclimits.h
limit_memory
void limit_memory(unsigned long limit)
Definition
proclimits.h:30
stddef.h
bad_alloc
Definition
GLOBAL_BAD_ALLOC.cpp:46
terminate.h
Generated by
1.9.8