Skip to content

Commit

Permalink
Update macro
Browse files Browse the repository at this point in the history
  • Loading branch information
endurodave committed Dec 30, 2024
1 parent dbd1e42 commit 90d21c1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions xallocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 90d21c1

Please sign in to comment.