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 192 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 221 of file memory_pool.h.

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

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 202 of file memory_pool.h.

202 { 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:71

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 229 of file memory_pool.h.

229  {
230  memory_pool<Alloc> &self = *reinterpret_cast<memory_pool<Alloc>*>(pool_id);
231  const size_t unit_size = sizeof(typename Alloc::value_type);
232  __TBBMALLOC_ASSERT( 0 == bytes%unit_size, NULL);
233  void *ptr;
234  __TBB_TRY { ptr = self.my_alloc.allocate( bytes/unit_size ); }
235  __TBB_CATCH(...) { return 0; }
236  return ptr;
237 }
#define __TBB_TRY
Definition: tbb_stddef.h:287
#define __TBB_CATCH(e)
Definition: tbb_stddef.h:288
#define __TBBMALLOC_ASSERT(a, b)
Definition: memory_pool.h:41

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 245 of file memory_pool.h.

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

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 193 of file memory_pool.h.


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

Copyright © 2005-2019 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.