Add and use a macro to define placement-new-only allocators

This is for structs that utilize over-allocation, either flexible array
members, or which store optional additional objects in the same allocation
block.
This commit is contained in:
Chris Robinson
2018-11-22 07:06:42 -08:00
parent ab6db9a589
commit ba8c865513
2 changed files with 5 additions and 3 deletions
+1 -3
View File
@@ -61,9 +61,7 @@ struct Compressor {
ALfloat LastAttack;
ALfloat LastGainDev;
void *operator new(size_t size) = delete;
void *operator new(size_t /*size*/, void *ptr) noexcept { return ptr; }
void operator delete(void *block) noexcept { al_free(block); }
DEF_PLACE_NEWDEL()
};
/* The compressor is initialized with the following settings:
+4
View File
@@ -31,6 +31,10 @@ int al_is_sane_alignment_allocator(void) noexcept;
} \
void operator delete(void *block) noexcept { al_free(block); }
#define DEF_PLACE_NEWDEL() \
void *operator new(size_t /*size*/, void *ptr) noexcept { return ptr; } \
void operator delete(void *block) noexcept { al_free(block); }
namespace al {
template<typename T, size_t alignment=DEF_ALIGN>