I am experimenting with updating our combined fixed-block memory allocation block to take advantage of features like C ++ 11.
Currently, it is possible to force distribution of any object anywhere that should be sent to the correct pool by overriding the global new operator in the traditional way, for example
void* operator new (std::size_t size) { // if-cascade just for simplest possible example if ( size <= 64 ) { return g_BlockPool64.Allocate(); } else if ( size <= 256 ) { return g_BlockPool256.Allocate(); } // etc .. else assume arguendo that we know the following will work properly else return malloc(size); }
In many cases, we could improve performance if objects could be sent to different pools depending on type types such as is_trivially_destructible . Is it possible to create a template global new operator that knows about the distributed type, and not just the requested size? Something equivalent
template<class T> void *operator new( size_t size) { if ( size < 64 ) { return std::is_trivially_destructible<T>::value ? g_BlockPool64_A.Allocate() : g_BlockPool64_B.Allocate(); }
Overriding the new element operator in each class will not work here; we really need this to automatically work for any placement anywhere. Posting a new one won't work: requiring each address to look like
Foo *p = new (mempool<Foo>) Foo();
too bulky and people will forget to use it.
c ++ c ++ 11 typetraits
Crashworks
source share