21 #ifndef __TBB_scalable_allocator_H 22 #define __TBB_scalable_allocator_H 30 #if !defined(__cplusplus) && __ICC==1100 31 #pragma warning (push) 32 #pragma warning (disable: 991) 40 #define __TBB_EXPORTED_FUNC __cdecl 42 #define __TBB_EXPORTED_FUNC 86 TBBMALLOC_INVALID_PARAM,
87 TBBMALLOC_UNSUPPORTED,
90 } ScalableAllocationResult;
95 TBBMALLOC_USE_HUGE_PAGES,
97 USE_HUGE_PAGES = TBBMALLOC_USE_HUGE_PAGES,
100 TBBMALLOC_SET_SOFT_HEAP_LIMIT
101 } AllocationModeParam;
111 TBBMALLOC_CLEAN_ALL_BUFFERS,
114 TBBMALLOC_CLEAN_THREAD_BUFFERS
115 } ScalableAllocationCmd;
131 typedef void *(*rawAllocType)(intptr_t pool_id,
size_t &bytes);
133 typedef int (*rawFreeType)(intptr_t pool_id,
void* raw_ptr,
size_t raw_bytes);
145 struct MemPoolPolicy {
147 TBBMALLOC_POOL_VERSION = 1
157 unsigned fixedPool : 1,
162 MemPoolPolicy(rawAllocType pAlloc_, rawFreeType pFree_,
163 size_t granularity_ = 0,
bool fixedPool_ =
false,
164 bool keepAllMemory_ =
false) :
165 pAlloc(pAlloc_), pFree(pFree_), granularity(granularity_), version(TBBMALLOC_POOL_VERSION),
166 fixedPool(fixedPool_), keepAllMemory(keepAllMemory_),
174 POOL_OK = TBBMALLOC_OK,
176 INVALID_POLICY = TBBMALLOC_INVALID_PARAM,
178 UNSUPPORTED_POLICY = TBBMALLOC_UNSUPPORTED,
180 NO_MEMORY = TBBMALLOC_NO_MEMORY,
182 NO_EFFECT = TBBMALLOC_NO_EFFECT
185 MemPoolError pool_create_v1(intptr_t pool_id,
const MemPoolPolicy *policy,
186 rml::MemoryPool **pool);
188 bool pool_destroy(MemoryPool* memPool);
189 void *pool_malloc(MemoryPool* memPool,
size_t size);
190 void *pool_realloc(MemoryPool* memPool,
void *
object,
size_t size);
191 void *pool_aligned_malloc(MemoryPool* mPool,
size_t size,
size_t alignment);
192 void *pool_aligned_realloc(MemoryPool* mPool,
void *ptr,
size_t size,
size_t alignment);
193 bool pool_reset(MemoryPool* memPool);
194 bool pool_free(MemoryPool *memPool,
void *
object);
195 MemoryPool *pool_identify(
void *
object);
201 #ifndef __TBB_NO_IMPLICIT_LINKAGE 202 #define __TBB_NO_IMPLICIT_LINKAGE 1 203 #include "tbb_stddef.h" 204 #undef __TBB_NO_IMPLICIT_LINKAGE 206 #include "tbb_stddef.h" 209 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC 215 #if _MSC_VER && !defined(__INTEL_COMPILER) 217 #pragma warning (push) 218 #pragma warning (disable: 4100) 224 #if TBB_USE_EXCEPTIONS 226 template<
typename E> __TBB_NOINLINE(
void throw_exception(
const E &e) );
231 void throw_exception(
const E &e) {
243 class scalable_allocator {
245 typedef typename internal::allocator_type<T>::value_type value_type;
246 typedef value_type* pointer;
247 typedef const value_type* const_pointer;
248 typedef value_type& reference;
249 typedef const value_type& const_reference;
250 typedef size_t size_type;
251 typedef ptrdiff_t difference_type;
252 template<
class U>
struct rebind {
253 typedef scalable_allocator<U> other;
256 scalable_allocator() throw() {}
257 scalable_allocator(
const scalable_allocator& ) throw() {}
258 template<
typename U> scalable_allocator(
const scalable_allocator<U>&) throw() {}
260 pointer address(reference x)
const {
return &x;}
261 const_pointer address(const_reference x)
const {
return &x;}
264 pointer allocate( size_type n,
const void* =0 ) {
265 pointer p =
static_cast<pointer
>(
scalable_malloc( n *
sizeof(value_type) ) );
267 internal::throw_exception(std::bad_alloc());
272 void deallocate( pointer p, size_type ) {
277 size_type max_size()
const throw() {
278 size_type absolutemax =
static_cast<size_type
>(-1) /
sizeof (value_type);
279 return (absolutemax > 0 ? absolutemax : 1);
281 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC 282 template<
typename U,
typename... Args>
283 void construct(U *p, Args&&... args)
284 { ::new((
void *)p) U(
std::forward<Args>(args)...); }
286 #if __TBB_CPP11_RVALUE_REF_PRESENT 287 void construct( pointer p, value_type&& value ) { ::new((
void*)(p)) value_type(
std::move( value ) ); }
289 void construct( pointer p,
const value_type& value ) {::new((
void*)(p)) value_type(value);}
291 void destroy( pointer p ) {p->~value_type();}
294 #if _MSC_VER && !defined(__INTEL_COMPILER) 295 #pragma warning (pop) 301 class scalable_allocator<void> {
303 typedef void* pointer;
304 typedef const void* const_pointer;
305 typedef void value_type;
306 template<
class U>
struct rebind {
307 typedef scalable_allocator<U> other;
311 template<
typename T,
typename U>
312 inline bool operator==(
const scalable_allocator<T>&,
const scalable_allocator<U>& ) {
return true;}
314 template<
typename T,
typename U>
315 inline bool operator!=(
const scalable_allocator<T>&,
const scalable_allocator<U>& ) {
return false;}
320 #if (__TBB_BUILD || __TBBMALLOC_BUILD) && !defined(__TBBMALLOC_NO_IMPLICIT_LINKAGE) 321 #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1 324 #if !__TBBMALLOC_NO_IMPLICIT_LINKAGE 326 #pragma comment(lib, "tbbmalloc_debug.lib") 328 #pragma comment(lib, "tbbmalloc.lib") 337 #if !defined(__cplusplus) && __ICC==1100 338 #pragma warning (pop) int __TBB_EXPORTED_FUNC scalable_posix_memalign(void **memptr, size_t alignment, size_t size)
The "posix_memalign" analogue.
void *__TBB_EXPORTED_FUNC scalable_malloc(size_t size)
The "malloc" analogue to allocate block of memory of size bytes.
Definition: _tbb_windef.h:37
void *__TBB_EXPORTED_FUNC scalable_aligned_malloc(size_t size, size_t alignment)
The "_aligned_malloc" analogue.
void *__TBB_EXPORTED_FUNC scalable_realloc(void *ptr, size_t size)
The "realloc" analogue complementing scalable_malloc.
size_t __TBB_EXPORTED_FUNC scalable_msize(void *ptr)
The analogue of _msize/malloc_size/malloc_usable_size.
Definition: _flow_graph_async_msg_impl.h:32
void __TBB_EXPORTED_FUNC scalable_free(void *ptr)
The "free" analogue to discard a previously allocated piece of memory.
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
void *__TBB_EXPORTED_FUNC scalable_aligned_realloc(void *ptr, size_t size, size_t alignment)
The "_aligned_realloc" analogue.
int __TBB_EXPORTED_FUNC scalable_allocation_command(int cmd, void *param)
Call TBB allocator-specific commands.
void __TBB_EXPORTED_FUNC scalable_aligned_free(void *ptr)
The "_aligned_free" analogue.
int __TBB_EXPORTED_FUNC scalable_allocation_mode(int param, intptr_t value)
Set TBB allocator-specific allocation modes.
void *__TBB_EXPORTED_FUNC scalable_calloc(size_t nobj, size_t size)
The "calloc" analogue complementing scalable_malloc.