Updated: Global replacement of memory allocation routines for OS X is added into Intel Threading Building Blocks v4.3. You can do the replacement either by loading libtbbmalloc_proxy.dylib
at program load time using the DYLD_INSERT_LIBRARIES environment variable, or by linking the main executable file with the proxy library. See more details in the TBB User Guide. Prior to 4.3, this functionality was unavailable for OS X.
The canonical way to replace new
is to define your own version of it. By the C++ standard, the following routines declared in <new>
should be defined in the global namespace:
void* operator new(std::size_t size);
void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
void operator delete(void* ptr) noexcept;
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
void* operator new[](std::size_t size);
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;
void operator delete[](void* ptr) noexcept;
void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
By default, these functions are defined (implemented) in the language support library; but a program is allowed to redefine these functions. So you might implement these functions to use the TBB memory allocator, e.g.
void* operator new( std::size_t object_size )
{
void* mem = scalable_malloc( object_size );
if (mem==NULL) throw std::bad_alloc();
return mem;
}
void* operator new(std::size_t object_size, const std::nothrow_t&) noexcept
{
return scalable_malloc( object_size );
}
and etc.
See also: