From 90d21c1801b87e51017cf2096087999bab54b1f3 Mon Sep 17 00:00:00 2001 From: "BOOK-0CD3P8P8FE\\endur" Date: Mon, 30 Dec 2024 14:26:40 -0800 Subject: [PATCH] Update macro --- xallocator.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xallocator.h b/xallocator.h index ff176df..705a1d9 100644 --- a/xallocator.h +++ b/xallocator.h @@ -70,25 +70,34 @@ void *xrealloc(void *ptr, size_t size); /// Output allocator statistics to the standard output void xalloc_stats(); -// Macro to overload new/delete with xalloc/xfree +// Macro to overload new/delete with xalloc/xfree. Add macro to any class to enable +// fixed-block memory allocation. Add to a base class provides fixed-block memory +// for the base and all derived classes. #define XALLOCATOR \ public: \ void* operator new(size_t size) { \ return xmalloc(size); \ } \ - void operator delete(void* pObject) { \ - xfree(pObject); \ - } \ void* operator new(size_t size, void* mem) { \ return mem; \ } \ + void* operator new(size_t size, const std::nothrow_t& nt) { \ + return xmalloc(size); \ + } \ void* operator new[](size_t size) { \ return xmalloc(size); \ } \ + void operator delete(void* pObject) { \ + xfree(pObject); \ + } \ + void operator delete(void* pObject, const std::nothrow_t& nt) { \ + xfree(pObject); \ + } \ void operator delete[](void* pData) { \ xfree(pData); \ } + #ifdef __cplusplus } #endif