Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::interface6::memory_pool< Alloc > Class Template Reference

Thread-safe growable pool allocator for variable-size requests. More...

#include <memory_pool.h>

Inheritance diagram for tbb::interface6::memory_pool< Alloc >:
Collaboration diagram for tbb::interface6::memory_pool< Alloc >:

Public Member Functions

 memory_pool (const Alloc &src=Alloc())
 construct pool with underlying allocator More...
 
 ~memory_pool ()
 destroy pool More...
 
- Public Member Functions inherited from tbb::interface6::internal::pool_base
void recycle ()
 Reset pool to reuse its memory (free all objects at once) More...
 
voidmalloc (size_t size)
 The "malloc" analogue to allocate block of memory of size bytes. More...
 
void free (void *ptr)
 The "free" analogue to discard a previously allocated piece of memory. More...
 
voidrealloc (void *ptr, size_t size)
 The "realloc" analogue complementing pool_malloc. More...
 

Static Private Member Functions

static voidallocate_request (intptr_t pool_id, size_t &bytes)
 
static int deallocate_request (intptr_t pool_id, void *, size_t raw_bytes)
 

Private Attributes

Alloc my_alloc
 

Additional Inherited Members

- Protected Member Functions inherited from tbb::interface6::internal::pool_base
void destroy ()
 destroy pool - must be called in a child class More...
 
- Protected Attributes inherited from tbb::interface6::internal::pool_base
rml::MemoryPool * my_pool
 

Detailed Description

template<typename Alloc>
class tbb::interface6::memory_pool< Alloc >

Thread-safe growable pool allocator for variable-size requests.

Definition at line 188 of file memory_pool.h.

Constructor & Destructor Documentation

◆ memory_pool()

template<typename Alloc >
tbb::interface6::memory_pool< Alloc >::memory_pool ( const Alloc &  src = Alloc())
explicit

construct pool with underlying allocator

Definition at line 217 of file memory_pool.h.

217  : my_alloc(src) {
218  rml::MemPoolPolicy args(allocate_request, deallocate_request,
219  sizeof(typename Alloc::value_type));
220  rml::MemPoolError res = rml::pool_create_v1(intptr_t(this), &args, &my_pool);
221  if (res!=rml::POOL_OK)
222  tbb::internal::throw_exception(std::runtime_error("Can't create pool"));
223 }
static void * allocate_request(intptr_t pool_id, size_t &bytes)
Definition: memory_pool.h:225
static int deallocate_request(intptr_t pool_id, void *, size_t raw_bytes)
Definition: memory_pool.h:241
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()

References tbb::interface6::memory_pool< Alloc >::allocate_request(), tbb::interface6::memory_pool< Alloc >::deallocate_request(), tbb::interface6::internal::pool_base::my_pool, and tbb::internal::throw_exception().

Here is the call graph for this function:

◆ ~memory_pool()

template<typename Alloc>
tbb::interface6::memory_pool< Alloc >::~memory_pool ( )
inline

destroy pool

Definition at line 198 of file memory_pool.h.

198 { destroy(); } // call the callbacks first and destroy my_alloc latter
void destroy()
destroy pool - must be called in a child class
Definition: memory_pool.h:67

References tbb::interface6::internal::pool_base::destroy().

Here is the call graph for this function:

Member Function Documentation

◆ allocate_request()

template<typename Alloc >
void * tbb::interface6::memory_pool< Alloc >::allocate_request ( intptr_t  pool_id,
size_t &  bytes 
)
staticprivate

Definition at line 225 of file memory_pool.h.

225  {
226  memory_pool<Alloc> &self = *reinterpret_cast<memory_pool<Alloc>*>(pool_id);
227  const size_t unit_size = sizeof(typename Alloc::value_type);
228  __TBBMALLOC_ASSERT( 0 == bytes%unit_size, NULL);
229  void *ptr;
230  __TBB_TRY { ptr = self.my_alloc.allocate( bytes/unit_size ); }
231  __TBB_CATCH(...) { return 0; }
232  return ptr;
233 }
#define __TBB_CATCH(e)
Definition: tbb_stddef.h:284
#define __TBBMALLOC_ASSERT(a, b)
Definition: memory_pool.h:37
#define __TBB_TRY
Definition: tbb_stddef.h:283

References __TBB_CATCH, __TBB_TRY, and __TBBMALLOC_ASSERT.

Referenced by tbb::interface6::memory_pool< Alloc >::memory_pool().

Here is the caller graph for this function:

◆ deallocate_request()

template<typename Alloc >
int tbb::interface6::memory_pool< Alloc >::deallocate_request ( intptr_t  pool_id,
void raw_ptr,
size_t  raw_bytes 
)
staticprivate

Definition at line 241 of file memory_pool.h.

241  {
242  memory_pool<Alloc> &self = *reinterpret_cast<memory_pool<Alloc>*>(pool_id);
243  const size_t unit_size = sizeof(typename Alloc::value_type);
244  __TBBMALLOC_ASSERT( 0 == raw_bytes%unit_size, NULL);
245  self.my_alloc.deallocate( static_cast<typename Alloc::value_type*>(raw_ptr), raw_bytes/unit_size );
246  return 0;
247 }
#define __TBBMALLOC_ASSERT(a, b)
Definition: memory_pool.h:37

References __TBBMALLOC_ASSERT.

Referenced by tbb::interface6::memory_pool< Alloc >::memory_pool().

Here is the caller graph for this function:

Member Data Documentation

◆ my_alloc

template<typename Alloc>
Alloc tbb::interface6::memory_pool< Alloc >::my_alloc
private

Definition at line 189 of file memory_pool.h.


The documentation for this class was generated from the following file:

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.