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...
void * | malloc (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...
void * | realloc (void *ptr, size_t size)
| The "realloc" analogue complementing pool_malloc. More...

## Static Private Member Functions

static void * | allocate_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.

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

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.

{ destroy(); } // call the callbacks first and destroy my_alloc latter
tbb::interface6::internal::pool_base::destroy
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
| ) |  |

static private

Definition at line 225 of file memory_pool.h.

{
memory_pool<Alloc> &self = *reinterpret_cast<memory_pool<Alloc>*>(pool_id);
const size_t unit_size = sizeof(typename Alloc::value_type);
__TBBMALLOC_ASSERT( 0 == bytes%unit_size, NULL);
void *ptr;
__TBB_TRY { ptr = self.my_alloc.allocate( bytes/unit_size ); }
__TBB_CATCH(...) { return 0; }
return ptr;
}
__TBBMALLOC_ASSERT
#define __TBBMALLOC_ASSERT(a, b)
Definition: memory_pool.h:37
__TBB_CATCH
#define __TBB_CATCH(e)
Definition: tbb_stddef.h:284
__TBB_TRY
#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
| ) |  |

static private

Definition at line 241 of file memory_pool.h.

{
memory_pool<Alloc> &self = *reinterpret_cast<memory_pool<Alloc>*>(pool_id);
const size_t unit_size = sizeof(typename Alloc::value_type);
__TBBMALLOC_ASSERT( 0 == raw_bytes%unit_size, NULL);
self.my_alloc.deallocate( static_cast<typename Alloc::value_type*>(raw_ptr), raw_bytes/unit_size );
return 0;
}

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:

- memory_pool.h

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.