31 #include "../my_config.h"
54 #ifdef LIBDAR_SPECIAL_ALLOC
74 const on_pool & operator = (
const on_pool & ref) {
return *
this; };
83 void *
operator new(
size_t n_byte) {
void *ret = alloc(n_byte,
nullptr);
if(ret ==
nullptr)
throw std::bad_alloc();
return ret; };
89 void *
operator new(
size_t n_byte,
const std::nothrow_t & nothrow_value) {
return alloc(n_byte,
nullptr); };
95 void *
operator new[](
size_t n_byte) {
void *ret = alloc(n_byte,
nullptr);
if(ret ==
nullptr)
throw std::bad_alloc();
return ret; };
101 void *
operator new[](
size_t n_byte,
const std::nothrow_t & nothrow_value) {
return alloc(n_byte,
nullptr); };
107 void *
operator new(
size_t n_byte, memory_pool *p) {
return alloc(n_byte, p); };
114 void *
operator new[] (
size_t n_byte, memory_pool *p) {
return alloc(n_byte, p); };
118 void operator delete(
void *ptr, memory_pool *p) { dealloc(ptr); };
122 void operator delete[](
void *ptr, memory_pool *p) { dealloc(ptr); };
126 void operator delete(
void *ptr) { dealloc(ptr); };
130 void operator delete[](
void *ptr) { dealloc(ptr); };
140 #ifdef LIBDAR_SPECIAL_ALLOC
141 memory_pool *
get_pool()
const {
return dynamic ? (((pool_ptr *)
this) - 1)->reserve :
nullptr; };
146 template <
class T>
void meta_new(T * & ptr,
size_t num)
148 #ifdef LIBDAR_SPECIAL_ALLOC
149 size_t byte = num *
sizeof(T);
154 ptr = (T *)
new (std::nothrow)
char [byte];
156 ptr =
new (std::nothrow) T[num];
162 template <
class T>
void meta_delete(T * ptr)
164 #ifdef LIBDAR_SPECIAL_ALLOC
168 delete [] (
char *)(ptr);
175 #ifdef LIBDAR_SPECIAL_ALLOC
183 memory_pool *reserve;
194 void dynamic_init()
const {
const_cast<on_pool *
>(
this)->dynamic = (alloc_not_constructed ==
this); alloc_not_constructed =
nullptr; };
202 static void *alloc(
size_t size, memory_pool *p);
208 static void dealloc(
void *ptr);
210 #ifdef LIBDAR_SPECIAL_ALLOC
211 thread_local
static on_pool * alloc_not_constructed;
are defined here basic integer types that tend to be portable
class memory_pool allocates and recycles blocks of memory for better performances it is expected to b...
memory_pool * get_pool() const
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
this is the base class of object that can provide dynamically allocated memory blocks ...