SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Malloc.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 #ifndef swcdb_core_Malloc_h
7 #define swcdb_core_Malloc_h
8 
9 #include <new>
10 #include <thread>
11 #include <chrono>
12 
20 #if !defined(__clang__)
21 #define SWC_MALLOC_NEW_ATTRIBS __attribute__((__nothrow__))
22 #define SWC_MALLOC_ATTRIBS SWC_CAN_INLINE
23 #else
24 #define SWC_MALLOC_NEW_ATTRIBS
25 #define SWC_MALLOC_ATTRIBS
26 #endif
27 
28 
29 
30 namespace SWC {
31 
32 class Memory {
33  public:
34 
35  static SWC_MALLOC_FUNC
36  void* allocate(const size_t sz) noexcept;
37 
38  static SWC_MALLOC_FUNC
39  void* allocate(const size_t sz, std::align_val_t al) noexcept;
40 
41  static
42  void free(void* ptr) noexcept;
43 
44 };
45 
46 }
47 
48 
49 
50 extern SWC_MALLOC_ATTRIBS
51  void* operator new(const size_t sz)
53 extern SWC_MALLOC_ATTRIBS
54  void* operator new[](size_t sz)
56 extern SWC_MALLOC_ATTRIBS
57  void* operator new(size_t sz, const std::nothrow_t&)
59 extern SWC_MALLOC_ATTRIBS
60  void* operator new[](size_t sz, const std::nothrow_t&)
62 
63 extern SWC_MALLOC_ATTRIBS
64  void* operator new(const size_t sz, std::align_val_t al)
66 extern SWC_MALLOC_ATTRIBS
67  void* operator new[](size_t sz, std::align_val_t al)
69 extern SWC_MALLOC_ATTRIBS
70  void* operator new(size_t sz, std::align_val_t al, const std::nothrow_t&)
72 extern SWC_MALLOC_ATTRIBS
73  void* operator new[](size_t sz, std::align_val_t al, const std::nothrow_t&)
75 
76 
77 extern SWC_MALLOC_ATTRIBS
78  void operator delete(void* ptr) noexcept;
79 extern SWC_MALLOC_ATTRIBS
80  void operator delete[](void* ptr) noexcept;
81 extern SWC_MALLOC_ATTRIBS
82  void operator delete(void* ptr, size_t sz) noexcept;
83 extern SWC_MALLOC_ATTRIBS
84  void operator delete[](void* ptr, size_t sz) noexcept;
85 
86 extern SWC_MALLOC_ATTRIBS
87  void operator delete(void* ptr, std::align_val_t al) noexcept;
88 extern SWC_MALLOC_ATTRIBS
89  void operator delete[](void* ptr, std::align_val_t al) noexcept;
90 extern SWC_MALLOC_ATTRIBS
91  void operator delete(void* ptr, size_t sz, std::align_val_t al) noexcept;
92 extern SWC_MALLOC_ATTRIBS
93  void operator delete[](void* ptr, size_t sz, std::align_val_t al) noexcept;
94 
95 
96 
98 void* operator new(const size_t sz) {
99  return SWC::Memory::allocate(sz);
100 }
101 
103 void* operator new(size_t sz, const std::nothrow_t&) {
104  return SWC::Memory::allocate(sz);
105 }
106 
108 void* operator new[](size_t sz) {
109  return SWC::Memory::allocate(sz);
110 }
111 
113 void* operator new[](size_t sz, const std::nothrow_t&) {
114  return SWC::Memory::allocate(sz);
115 }
116 
117 
119 void* operator new(const size_t sz, std::align_val_t al) {
120  return SWC::Memory::allocate(sz, al);
121 }
122 
124 void* operator new(size_t sz, std::align_val_t al, const std::nothrow_t&) {
125  return SWC::Memory::allocate(sz, al);
126 }
127 
129 void* operator new[](size_t sz, std::align_val_t al) {
130  return SWC::Memory::allocate(sz, al);
131 }
132 
134 void* operator new[](size_t sz, std::align_val_t al, const std::nothrow_t&) {
135  return SWC::Memory::allocate(sz, al);
136 }
137 
138 
139 
141 void operator delete(void* ptr) noexcept {
142  SWC::Memory::free(ptr);
143 }
144 
146 void operator delete[](void* ptr) noexcept {
147  SWC::Memory::free(ptr);
148 }
149 
151 void operator delete(void* ptr, size_t ) noexcept {
152  SWC::Memory::free(ptr);
153 }
154 
156 void operator delete[](void* ptr, size_t ) noexcept {
157  SWC::Memory::free(ptr);
158 }
159 
160 
162 void operator delete(void* ptr, std::align_val_t) noexcept {
163  SWC::Memory::free(ptr);
164 }
165 
167 void operator delete[](void* ptr, std::align_val_t) noexcept {
168  SWC::Memory::free(ptr);
169 }
170 
172 void operator delete(void* ptr, size_t, std::align_val_t) noexcept {
173  SWC::Memory::free(ptr);
174 }
175 
177 void operator delete[](void* ptr, size_t, std::align_val_t) noexcept {
178  SWC::Memory::free(ptr);
179 }
180 
181 
187 namespace SWC { }
188 
189 //#ifdef SWC_IMPL_SOURCE
190 #include "swcdb/core/Malloc.cc"
191 //#endif
192 
193 #endif // swcdb_core_Malloc_h
SWC::Memory
Definition: Malloc.h:32
SWC::Memory::free
static void free(void *ptr) noexcept
Definition: Malloc.cc:53
SWC::Memory::allocate
static SWC_MALLOC_FUNC void * allocate(const size_t sz) noexcept
Definition: Malloc.cc:14
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
Malloc.cc
SWC_MALLOC_ATTRIBS
#define SWC_MALLOC_ATTRIBS
Definition: Malloc.h:22
SWC_MALLOC_FUNC
#define SWC_MALLOC_FUNC
Definition: Compat.h:109
SWC_MALLOC_NEW_ATTRIBS
#define SWC_MALLOC_NEW_ATTRIBS
Definition: Malloc.h:21