Concurrent with this is the need to replace the system allocator on Win32 with TnFOX's one which typically yields a 6x speed increase for multithreaded C++ programs. A unified system is required for all this as there is only one global new and delete operator. It is rather important that you read and understand the following discussion.
Due to how C++ (and C) works, there is one global new
and delete
operator which supposedly can be wholly replaced by any program according to the standard. This isn't actually true - on Win32, you can only replace per binary (DLL or EXE) and on GNU/ELF/POSIX your operator replacements get happily overrided by any shared objects loaded after your binary. It gets worse - when working with containers or any code which speculatively allocates memory (eg; buffering), a container can quickly come to consist of blocks allocated from a multitude of memory pools all at once leaving us with no choice other than to permit any thread with any memory pool currently set to be able to free any other allocation, no matter where it was allocated. Furthermore, we must also tolerate other parts of the C library or STL allocating with the default allocator and freeing using ours (GCC is particularly bad for this when optimisation is turned on).
Classes | |
class | FX::aligned_allocator< T, alignment > |
An aligning memory allocator for the STL. More... | |
class | FX::FXMemoryPool |
A threadsafe custom memory pool. More... | |
Functions | |
FXAPI FXMALLOCATTR void * | FX::malloc (size_t size, FXMemoryPool *heap=0, FXuint alignment=0) throw () |
FXAPI FXMALLOCATTR void * | FX::calloc (size_t no, size_t size, FXMemoryPool *heap=0, FXuint alignment=0) throw () |
FXAPI FXMALLOCATTR void * | FX::realloc (void *p, size_t size, FXMemoryPool *heap=0) throw () |
FXAPI void | FX::free (void *p, FXMemoryPool *heap=0) throw () |
template<typename T> | |
FXMALLOCATTR T * | FX::realloc (T *p, size_t size, FXMemoryPool *heap=0) throw () |
template<typename T> | |
void | FX::free (T *p, FXMemoryPool *heap=0) throw () |
FXMALLOCATTR char * | FX::strdup (const char *str) throw () |
FXAPI void | FX::failonfree (void *p, FXMemoryPool *heap=0) throw () |
FXAPI void | FX::unfailonfree (void *p, FXMemoryPool *heap=0) throw () |
FXDLLPUBLIC FXMALLOCATTR void * | operator new (size_t size, FX::FXMemoryPool *heap, FX::FXuint alignment=0) throw (std::bad_alloc) |
FXDLLPUBLIC FXMALLOCATTR void * | operator new[] (size_t size, FX::FXMemoryPool *heap, FX::FXuint alignment=0) throw (std::bad_alloc) |
FXDLLPUBLIC void | operator delete (void *p, FX::FXMemoryPool *heap) throw () |
FXDLLPUBLIC void | operator delete[] (void *p, FX::FXMemoryPool *heap) throw () |
FXAPI FXMALLOCATTR void * | tnfxmalloc (size_t size) |
FXAPI FXMALLOCATTR void * | tnfxcalloc (size_t no, size_t size) |
FXAPI FXMALLOCATTR void * | tnfxrealloc (void *p, size_t size) |
FXAPI void | tnfxfree (void *p) |
FXDLLPUBLIC FXMALLOCATTR void * | operator new (size_t size) throw (std::bad_alloc) |
FXDLLPUBLIC FXMALLOCATTR void * | operator new[] (size_t size) throw (std::bad_alloc) |
FXDLLPUBLIC void | operator delete (void *p) throw () |
FXDLLPUBLIC void | operator delete[] (void *p) throw () |