Visible to Intel only — GUID: GUID-A8F5AF17-C640-4DA5-92D0-9340E46DE998
Visible to Intel only — GUID: GUID-A8F5AF17-C640-4DA5-92D0-9340E46DE998
memory_pool
A class template for scalable memory allocation from memory blocks provided by an underlying allocator.
Description
A memory_pool allocates and frees memory in a way that scales with the number of processors. The memory is obtained as big chunks from an underlying allocator specified by the template argument. The latter must satisfy the subset of the allocator requirements from the [allocator.requirements] ISO C++ Standard section. A memory_pool meet the Memory Pool named requirement.
API
Header
#include "oneapi/tbb/memory_pool.h"
Synopsis
namespace oneapi { namespace tbb { template <typename Alloc> class memory_pool { public: explicit memory_pool(const Alloc &src = Alloc()); memory_pool(const memory_pool& other) = delete; memory_pool& operator=(const memory_pool& other) = delete; ~memory_pool(); void recycle(); void *malloc(size_t size); void free(void* ptr); void *realloc(void* ptr, size_t size); }; } }
Member Functions
explicitmemory_pool(constAlloc&src=Alloc())
Effects: Constructs a memory pool with an instance of underlying memory allocator of type Alloc copied from src. Throws the bad_alloc exception if runtime fails to construct an instance of the class.
Examples
The code below provides a simple example of allocation from an extensible memory pool.
#define TBB_PREVIEW_MEMORY_POOL 1 #include "oneapi/tbb/memory_pool.h" ... oneapi::tbb::memory_pool<std::allocator<char> > my_pool; void* my_ptr = my_pool.malloc(10); my_pool.free(my_ptr);