-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcorenewoperator.cpp
More file actions
130 lines (110 loc) · 3.59 KB
/
Copy pathcorenewoperator.cpp
File metadata and controls
130 lines (110 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//************************************************************************************************
//
// This file is part of Crystal Class Library (R)
// Copyright (c) 2025 CCL Software Licensing GmbH.
// All Rights Reserved.
//
// Licensed for use under either:
// 1. a Commercial License provided by CCL Software Licensing GmbH, or
// 2. GNU Affero General Public License v3.0 (AGPLv3).
//
// You must choose and comply with one of the above licensing options.
// For more information, please visit ccl.dev.
//
// Filename : core/malloc/corenewoperator.cpp
// Description : Global new/delete operators
//
//************************************************************************************************
#include "core/public/coreplatform.h"
#if CORE_MALLOC_AVAILABLE
#include <new>
//************************************************************************************************
// Global new/delete operators
//************************************************************************************************
void* operator new (std::size_t size)
{
#if DEBUG
// setting the filename parameter to 0 prevents the debug heap from catching foreign unbalanced allocations
return core_malloc_debug ((unsigned int)size, nullptr, 0);
#else
return core_malloc ((unsigned int)size);
#endif
}
#if __cpp_decltype
void operator delete (void* memory) noexcept
#else
void operator delete (void* memory) throw ()
#endif
{
if(memory)
core_free (memory);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
void* operator new[] (std::size_t size)
{
#if DEBUG
return core_malloc_debug ((unsigned int)size, nullptr, 0);
#else
return core_malloc ((unsigned int)size);
#endif
}
#if __cpp_decltype
void operator delete[] (void* memory) noexcept
#else
void operator delete[] (void* memory) throw ()
#endif
{
if(memory)
core_free (memory);
}
//************************************************************************************************
// Global non-throwing new/delete operators
//************************************************************************************************
#if __cpp_decltype
void* operator new (std::size_t size, const std::nothrow_t& tag) noexcept
#else
void* operator new (std::size_t size, const std::nothrow_t& tag) throw ()
#endif
{
return operator new (size);
}
#if __cpp_decltype
void operator delete (void* memory, const std::nothrow_t& tag) noexcept
#else
void operator delete (void* memory, const std::nothrow_t& tag) throw ()
#endif
{
operator delete (memory);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
#if __cpp_decltype
void* operator new[] (std::size_t size, const std::nothrow_t& tag) noexcept
#else
void* operator new[] (std::size_t size, const std::nothrow_t& tag) throw ()
#endif
{
return operator new[] (size);
}
#if __cpp_decltype
void operator delete[] (void* memory, const std::nothrow_t& tag) noexcept
#else
void operator delete[] (void* memory, const std::nothrow_t& tag) throw ()
#endif
{
operator delete[] (memory);
}
//************************************************************************************************
// Global delete operators with size hint (C++14)
//************************************************************************************************
#if __cpp_decltype_auto
void operator delete (void* memory, size_t size) noexcept
{
operator delete (memory);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
void operator delete[] (void* memory, size_t size) noexcept
{
operator delete[] (memory);
}
#endif
#endif