CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
OdHeap.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24
25#ifndef _OD_HEAPOPERATORS_INCLUDED_
26#define _OD_HEAPOPERATORS_INCLUDED_
27
28#include "OdAlloc.h"
29#include <new>
30#include <exception>
31
32#ifdef __BCPLUSPLUS__ // borland compiler does not support "placement delete"
33
37#define ODRX_HEAP_OPERATORS() \
38void* operator new(size_t s) { return ::odrxAlloc(s); }\
39void operator delete(void* p) { ::odrxFree(p); }\
40void* operator new[](size_t s) { return ::odrxAlloc(s); }\
41void operator delete[](void* p) { ::odrxFree(p); }\
42void *operator new(size_t, void* p) { return p; }\
43void *operator new[](size_t, void* p) { return p; }
44
45#elif defined(_MSC_VER) || (defined(__cplusplus) && (__cplusplus > 199711L))
46// MSVC ignores exception specs (and gives warning)
47// Dynamic exception specifications are deprecated in C++11
48
52#define ODRX_HEAP_OPERATORS() \
53void* operator new(size_t s)\
54{\
55 void* p = ::odrxAlloc(s);\
56 if ( !p ) NEW_HANDLER()\
57 return p;\
58}\
59void operator delete(void* p) { ::odrxFree(p); }\
60void* operator new[](size_t s)\
61{\
62 void* p = ::odrxAlloc(s);\
63 if ( !p ) NEW_HANDLER()\
64 return p;\
65}\
66void operator delete[](void* p) { ::odrxFree(p); }\
67void *operator new(size_t, void* p) { return p; }\
68void operator delete( void*, void* ) {}\
69void *operator new[](size_t, void* p) { return p; }\
70void operator delete[]( void*, void* ) {}
71
72#else
73
77#define ODRX_HEAP_OPERATORS() \
78void* operator new(size_t s) \
79{\
80 void* p = ::odrxAlloc(s);\
81 if ( !p ) NEW_HANDLER()\
82 return p;\
83}\
84void operator delete(void* p) { ::odrxFree(p); }\
85void* operator new[](size_t s) \
86{\
87 void* p = ::odrxAlloc(s);\
88 if ( !p ) NEW_HANDLER()\
89 return p;\
90}\
91void operator delete[](void* p) { ::odrxFree(p); }\
92void *operator new(size_t, void* p) throw() { return p; }\
93void operator delete( void*, void* ) {}\
94void *operator new[](size_t, void* p) throw() { return p; }\
95void operator delete[]( void*, void* ) {}
96
97#endif
98
102#define ODRX_NO_HEAP_OPERATORS() \
103void* operator new(size_t ) throw() { ODA_FAIL(); return 0; }\
104void operator delete(void* ) { ODA_FAIL(); std::terminate(); }\
105void* operator new[](size_t ) throw() { ODA_FAIL(); return 0; }\
106void operator delete[](void* ) { ODA_FAIL(); std::terminate(); }
107
108#ifdef OD_REDEFINE_HEAP_OPERATORS
109
113#define ODRX_USING_HEAP_OPERATORS(T) \
114void* operator new(size_t s) throw() { return T::operator new(s); }\
115void operator delete(void* p) { T::operator delete(p); }\
116void* operator new[](size_t s) throw() { return T::operator new(s); }\
117void operator delete[](void* p) { T::operator delete(p); }
118
119#else
120
124#define ODRX_USING_HEAP_OPERATORS(T) \
125using T::operator new;\
126using T::operator delete;\
127using T::operator new[];\
128using T::operator delete[]
129
130#endif
131
132
133#endif // _OD_HEAPOPERATORS_INCLUDED_