CFx SDK Documentation
2020SP3
SDK
CFx
dd_inc
OdAllocOp.h
Go to the documentation of this file.
1
// Copyright (C) 2002-2017, 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 Teigha(R) software pursuant to a license
16
// agreement with Open Design Alliance.
17
// Teigha(R) Copyright (C) 2002-2017 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
#ifndef __ODAALLOCOP_H__
24
#define __ODAALLOCOP_H__
25
#include <stdlib.h>
26
#include "
OdAllocExport.h
"
27
#include "
OdAlloc.h
"
28
#include <new>
29
30
// Duplicate symbol link errors result using PocketPC if we define our own new & delete
31
#if !defined(_WIN32_WCE)
32
33
#ifdef _MSC_VER
34
#pragma warning(disable: 4290) // C++ exception spec. ignored
35
#endif
36
37
#if (defined(__GNUC__) && __GNUC__ >= 5) || (defined(_MSC_VER) && _MSC_VER >= 1800) //VS2015 and newer or GCC 5 and newer (support sized deallocation)
38
#define ODRX_SIZED_DEALLOC_OPERATORS() \
39
void operator delete(void* p, std::size_t) \
40
{ \
41
if (!p) return; \
42
::odrxFree(p); \
43
} \
44
void operator delete[](void* p, std::size_t) \
45
{ \
46
if (!p) return; \
47
::odrxFree(p); \
48
}\
49
void operator delete(void* ptr, std::size_t s, const std::nothrow_t&) \
50
{ \
51
operator delete(ptr, s); \
52
} \
53
void operator delete[](void* ptr, std::size_t s, const std::nothrow_t&) \
54
{ \
55
operator delete[](ptr, s); \
56
} \
57
58
#else
59
#define ODRX_SIZED_DEALLOC_OPERATORS()
60
#endif
61
62
#define ODRX_NOTHROW_ALLOC_OPERATORS() \
63
void *operator new (size_t size, const std::nothrow_t&) throw() { return operator new(size); } \
64
void * operator new[] (::size_t count, const std::nothrow_t&) throw() { return operator new[](count); }\
65
void operator delete[](void *ptr, const std::nothrow_t&) throw() { operator delete[](ptr); } \
66
void operator delete (void *ptr, const std::nothrow_t&) throw() { operator delete(ptr); } \
67
68
#ifdef __GNUC__
69
#define ODRX_ALLOC_OPERATORS() \
70
void* operator new (size_t size) throw(std::bad_alloc) \
71
{ \
72
void* p = ::odrxAlloc(size); \
73
return p; \
74
} \
75
void operator delete (void *p) throw() \
76
{ \
77
if (!p) return; \
78
::odrxFree(p); \
79
} \
80
void* operator new[](size_t size) throw(std::bad_alloc) \
81
{ \
82
void* p = ::odrxAlloc(size); \
83
return p; \
84
} \
85
void operator delete[](void *p) throw() \
86
{ \
87
if (!p) return; \
88
::odrxFree(p); \
89
} \
90
ODRX_NOTHROW_ALLOC_OPERATORS() \
91
ODRX_SIZED_DEALLOC_OPERATORS() \
92
93
#else //__GNUC__
94
#define ODRX_ALLOC_OPERATORS() \
95
void* operator new (size_t size) throw(std::bad_alloc) \
96
{ \
97
void* p = ::odrxAlloc(size); \
98
/*Under GCC std::allocator allocates zero sizes via operator new (by default)*/
\
99
if (!p && size) throw std::bad_alloc(); \
100
return p; \
101
} \
102
void operator delete (void *p) throw() \
103
{ \
104
if (!p) return; \
105
::odrxFree(p); \
106
} \
107
void* operator new[](size_t size) throw(std::bad_alloc) \
108
{ \
109
void* p = ::odrxAlloc(size); \
110
if (!p && size) throw std::bad_alloc(); \
111
return p; \
112
} \
113
void operator delete[](void *p) throw() \
114
{ \
115
if (!p) return; \
116
::odrxFree(p); \
117
} \
118
ODRX_NOTHROW_ALLOC_OPERATORS() \
119
ODRX_SIZED_DEALLOC_OPERATORS() \
120
121
#endif //__GNUC__
122
#else
123
124
#define ODRX_ALLOC_OPERATORS()
125
#define ODRX_CRTDBG_MAP_ALLOC_OPERATORS()
126
127
#endif
128
129
// Support _CRTDBG_MAP_ALLOC memory allocation
131
#if (_MSC_VER >= 1200) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
132
133
#define ODRX_CRTDBG_MAP_ALLOC_OPERATORS() \
134
extern "C" { extern _CRTIMP void * __cdecl _malloc_dbg(size_t, int, const char *, int); } \
135
void* __cdecl operator new(size_t size, int type, const char* fname, int line) { return _malloc_dbg(size, type, fname, line); } \
136
void* __cdecl operator new[](size_t size, int type, const char* fname, int line) { return operator new(size, type, fname, line); } \
137
138
#else //_CRTDBG_MAP_ALLOC
139
140
#ifdef _MSC_VER
141
#define TD_CDECL __cdecl
142
#else
143
#define TD_CDECL
144
#endif
145
146
#if !defined(_WIN32_WCE)
147
#define ODRX_CRTDBG_MAP_ALLOC_OPERATORS() \
148
void* TD_CDECL operator new(size_t size, int, const char*,int) { return ::operator new(size); } \
149
void* TD_CDECL operator new[](size_t size, int, const char*, int) { return ::operator new[](size); }
150
151
#endif
152
153
#endif //_CRTDBG_MAP_ALLOC
154
#endif //__ODAALLOCOP_H__
OdAlloc.h
OdAllocExport.h
Generated on Mon Oct 12 2020 11:49:42