aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-09-11 03:59:53 -0700
committerChris Robinson <[email protected]>2019-09-11 03:59:53 -0700
commit5b37e2339bc91de3424b51600c3d3b96401d0b9c (patch)
tree4f816457b227ee511563b9b6f0d3fa91bd70b814 /common
parentc6c50484160435ee96e51eece154013fe6e48237 (diff)
Simplify flexible array member usage
Diffstat (limited to 'common')
-rw-r--r--common/almalloc.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/common/almalloc.h b/common/almalloc.h
index 785592bd..232294cc 100644
--- a/common/almalloc.h
+++ b/common/almalloc.h
@@ -27,8 +27,24 @@ void al_free(void *ptr) noexcept;
#define DEF_PLACE_NEWDEL() \
void *operator new(size_t /*size*/, void *ptr) noexcept { return ptr; } \
- void operator delete(void *block) noexcept { al_free(block); } \
- void operator delete(void* /*block*/, void* /*ptr*/) noexcept { }
+ void operator delete(void *block, void*) noexcept { al_free(block); } \
+ void operator delete(void *block) noexcept { al_free(block); }
+
+struct FamCount { size_t mCount; };
+
+#define DEF_FAM_NEWDEL(T, FamMem) \
+ static constexpr size_t Sizeof(size_t count) noexcept \
+ { return decltype(FamMem)::Sizeof(count, offsetof(T, FamMem)); } \
+ \
+ void *operator new(size_t /*size*/, FamCount fam) \
+ { \
+ if(void *ret{al_malloc(alignof(T), T::Sizeof(fam.mCount))}) \
+ return ret; \
+ throw std::bad_alloc(); \
+ } \
+ void operator delete(void *block, FamCount /*fam*/) { al_free(block); } \
+ void operator delete(void *block) noexcept { al_free(block); }
+
namespace al {