Skip to Main Content
Intel Threading Building Blocks
book

Intel Threading Building Blocks

by James Reinders
July 2007
Intermediate to advanced content levelIntermediate to advanced
332 pages
10h 4m
English
O'Reilly Media, Inc.
Content preview from Intel Threading Building Blocks

Replace new and delete

The C++ standard provides eight signatures, which you can replace with functions using the Threading Building Blocks scalable memory allocator. There are four pairs of new/delete operators, which provide throw/no-throw versions of each as well as scalar and array forms. Example 6-1 shows the complete list of signatures.

Example 6-1. ISO 14882 C++ new/delete

void* operator new(std::size_t size) throw(std::bad_alloc);
void* operator new(std::size_t size, const std::nothrow_t&) throw();
void* operator new[](std::size_t size) throw(std::bad_alloc);
void* operator new[](std::size_t size, const std::nothrow_t&) throw();
void  operator delete(void* ptr) throw();
void  operator delete(void* ptr, const std::nothrow_t&) throw();
void  operator delete[](void* ptr) throw();
void  operator delete[](void* ptr, const std::nothrow_t&) throw();

Replacing all eight signatures is the only way to ensure portability. Some implementations may simply implement the array forms in terms of the scalar forms, but relying on that could lead to more problems than it is worth if that assumption proves not to be true in the future.

The replacements you write for new and delete have to go in the right place (before any use of new or delete).

Actual code to do new/delete replacement can be found in Chapter 11 in Example 11-50 (“Replacement of new and delete functions, demonstration”).

Warning

Consult your C++ compiler documentation carefully to understand limitations and other issues. Understanding ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Rezaur Rahman

Publisher Resources

ISBN: 9780596514808Errata Page