CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
OdHeap.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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-2022 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
31#ifdef __BCPLUSPLUS__ // borland compiler does not support "placement delete"
32
36#define ODRX_HEAP_OPERATORS() \
37void* operator new(size_t s) { return ::odrxAlloc(s); }\
38void operator delete(void* p) { ::odrxFree(p); }\
39void* operator new[](size_t s) { return ::odrxAlloc(s); }\
40void operator delete[](void* p) { ::odrxFree(p); }\
41void *operator new(size_t, void* p) { return p; }\
42void *operator new[](size_t, void* p) { return p; }
43
44#elif defined(_MSC_VER) || (defined(__cplusplus) && (__cplusplus > 199711L))
45// MSVC ignores exception specs (and gives warning)
46// Dynamic exception specifications are deprecated in C++11
47
51#define ODRX_HEAP_OPERATORS() \
52void* operator new(size_t s)\
53{\
54 void* p = ::odrxAlloc(s);\
55 if ( !p ) NEW_HANDLER()\
56 return p;\
57}\
58void operator delete(void* p) { ::odrxFree(p); }\
59void* operator new[](size_t s)\
60{\
61 void* p = ::odrxAlloc(s);\
62 if ( !p ) NEW_HANDLER()\
63 return p;\
64}\
65void operator delete[](void* p) { ::odrxFree(p); }\
66void *operator new(size_t, void* p) { return p; }\
67void operator delete( void*, void* ) {}\
68void *operator new[](size_t, void* p) { return p; }\
69void operator delete[]( void*, void* ) {}
70
71#else
72
76#define ODRX_HEAP_OPERATORS() \
77void* operator new(size_t s) \
78{\
79 void* p = ::odrxAlloc(s);\
80 if ( !p ) NEW_HANDLER()\
81 return p;\
82}\
83void operator delete(void* p) { ::odrxFree(p); }\
84void* operator new[](size_t s) \
85{\
86 void* p = ::odrxAlloc(s);\
87 if ( !p ) NEW_HANDLER()\
88 return p;\
89}\
90void operator delete[](void* p) { ::odrxFree(p); }\
91void *operator new(size_t, void* p) throw() { return p; }\
92void operator delete( void*, void* ) {}\
93void *operator new[](size_t, void* p) throw() { return p; }\
94void operator delete[]( void*, void* ) {}
95
96#endif
97
98#if !defined(_MSC_VER) || (_MSC_VER < 1900)
99
103#define ODRX_NO_HEAP_OPERATORS() \
104void* operator new(size_t ) throw() { ODA_FAIL(); return 0; }\
105void operator delete(void* ) { ODA_FAIL(); throw OdError(eNotApplicable); }\
106void* operator new[](size_t ) throw() { ODA_FAIL(); return 0; }\
107void operator delete[](void* ) { ODA_FAIL(); throw OdError(eNotApplicable); }
108
109#else // defined(_MSC_VER) && (_MSC_VER >= 1900)
110
115#define ODRX_NO_HEAP_OPERATORS() \
116static void _throwOdError_eNotApplicable() { ODA_FAIL(); throw OdError(eNotApplicable); }\
117void* operator new(size_t ) throw() { ODA_FAIL(); return 0; }\
118void operator delete(void* ) { _throwOdError_eNotApplicable(); }\
119void* operator new[](size_t ) throw() { ODA_FAIL(); return 0; }\
120void operator delete[](void* ) { _throwOdError_eNotApplicable(); }
121
122#endif // defined(_MSC_VER) && (_MSC_VER >= 1900)
123
124#ifdef OD_REDEFINE_HEAP_OPERATORS
125
129#define ODRX_USING_HEAP_OPERATORS(T) \
130void* operator new(size_t s) throw() { return T::operator new(s); }\
131void operator delete(void* p) { T::operator delete(p); }\
132void* operator new[](size_t s) throw() { return T::operator new(s); }\
133void operator delete[](void* p) { T::operator delete(p); }
134
135#else
136
140#define ODRX_USING_HEAP_OPERATORS(T) \
141using T::operator new;\
142using T::operator delete;\
143using T::operator new[];\
144using T::operator delete[]
145
146#endif
147
148
149#endif // _OD_HEAPOPERATORS_INCLUDED_