1.. _fixed_pool_cls: 2 3fixed_pool 4========== 5 6.. note:: 7 To enable this feature, set the ``TBB_PREVIEW_MEMORY_POOL`` macro to 1. 8 9A class for scalable memory allocation from a buffer of fixed size. 10 11.. contents:: 12 :local: 13 :depth: 1 14 15Description 16*********** 17 18``fixed_pool`` allocates and frees memory in a way that scales with the number of processors. 19All the memory available for the allocation is initially passed through arguments of the constructor. 20``fixed_pool`` meet the :doc:`Memory Pool named requirement<../scalable_memory_pools>`. 21 22API 23*** 24 25Header 26------ 27 28.. code:: cpp 29 30 #include "oneapi/tbb/memory_pool.h" 31 32Synopsis 33-------- 34 35.. code:: cpp 36 37 namespace oneapi { 38 namespace tbb { 39 class fixed_pool { 40 public: 41 fixed_pool(void *buffer, size_t size); 42 fixed_pool(const fixed_pool& other) = delete; 43 fixed_pool& operator=(const fixed_pool& other) = delete; 44 ~fixed_pool(); 45 46 void recycle(); 47 void* malloc(size_t size); 48 void free(void* ptr); 49 void* realloc(void* ptr, size_t size); 50 }; 51 } // namespace tbb 52 } // namespace oneapi 53 54Member Functions 55---------------- 56 57.. cpp:function:: fixed_pool(void *buffer, size_t size) 58 59 **Effects**: Constructs a memory pool to manage the memory of size ``size`` pointed to by ``buffer``. 60 Throws the ``bad_alloc`` exception if the library fails to construct an instance of the class. 61 62Examples 63******** 64 65The code below provides a simple example of allocation from a fixed pool. 66 67.. code:: cpp 68 69 #define TBB_PREVIEW_MEMORY_POOL 1 70 #include "oneapi/tbb/memory_pool.h" 71 ... 72 char buf[1024*1024]; 73 oneapi::tbb::fixed_pool my_pool(buf, 1024*1024); 74 void* my_ptr = my_pool.malloc(10); 75 my_pool.free(my_ptr);} 76 77