Memory Allocation
摘要
This chapter discusses a critical part of any parallel program: scalable memory allocation, which includes the use of new as well as explicit calls to malloc, calloc, and so on. Scalable memory allocation can be used regardless of whether we use any other part of Threading Building Blocks (TBB). In addition to interfaces to use directly, TBB offers “proxy” libraries to automatically replace C/C++ functions for dynamic memory allocation, which is an easy, effective, and popular way to get a performance boost without any code changes. This is important and works regardless of how advanced you are in your usage of C++, specifically whether you use the modern and encouraged smart pointers (std::unique_ptr, std::shared_ptr, or std::weak_ptr) or the now discouraged raw pointers. The performance benefits of using a scalable memory allocator are significant because they directly address issues that would otherwise limit scaling and risk false sharing. TBB was among the first widely used scalable memory allocators, in no small part because it came free with TBB to help highlight the importance of including memory allocation considerations in any parallel program. It remains extremely popular today and is one of the best scalable memory allocators available.