Template class for scalable memory allocation from a buffer of fixed size.
class fixed_pool;
#define TBB_PREVIEW_MEMORY_POOL 1 #include "tbb/memory_pool.h"
A fixed_pool allocates and frees memory in a way that scales with the number of processors. All the memory available for the allocation is initially passed through arguments of the constructor. A fixed_pool models the Memory Pool concept described in Table 52.
#define TBB_PREVIEW_MEMORY_POOL 1 #include "tbb/memory_pool.h" ... char buf[1024*1024]; tbb::fixed_pool my_pool(buf, 1024*1024); void* my_ptr = my_pool.malloc(10); my_pool.free(my_ptr);}
The code above provides a simple example of allocation from a fixed pool.
namespace tbb { class fixed_pool : no_copy { public: fixed_pool(void *buffer, size_t size) throw(std::bad_alloc); ~fixed_pool(); void recycle(); void *malloc(size_t size); void free(void* ptr); void *realloc(void* ptr, size_t size); }; }
Member | Description |
---|---|
fixed_pool(void *buffer, size_t size) |
Constructs memory pool to manage the memory pointed by buffer and of size. Throws bad_alloc exception if runtime fails to construct an instance of the class. |