17 #ifndef __TBB_scalable_allocator_H
18 #define __TBB_scalable_allocator_H
26 #if !defined(__cplusplus) && __ICC==1100
27 #pragma warning (push)
28 #pragma warning (disable: 991)
36 #define __TBB_EXPORTED_FUNC __cdecl
38 #define __TBB_EXPORTED_FUNC
130 typedef void *(*rawAllocType)(intptr_t pool_id,
size_t &bytes);
132 typedef int (*rawFreeType)(intptr_t pool_id,
void* raw_ptr,
size_t raw_bytes);
144 struct MemPoolPolicy {
146 TBBMALLOC_POOL_VERSION = 1
156 unsigned fixedPool : 1,
161 MemPoolPolicy(rawAllocType pAlloc_, rawFreeType pFree_,
162 size_t granularity_ = 0,
bool fixedPool_ =
false,
163 bool keepAllMemory_ =
false) :
164 pAlloc(pAlloc_), pFree(pFree_), granularity(granularity_), version(TBBMALLOC_POOL_VERSION),
165 fixedPool(fixedPool_), keepAllMemory(keepAllMemory_),
184 MemPoolError pool_create_v1(intptr_t pool_id,
const MemPoolPolicy *policy,
185 rml::MemoryPool **pool);
187 bool pool_destroy(MemoryPool* memPool);
188 void *pool_malloc(MemoryPool* memPool,
size_t size);
189 void *pool_realloc(MemoryPool* memPool,
void *
object,
size_t size);
190 void *pool_aligned_malloc(MemoryPool* mPool,
size_t size,
size_t alignment);
191 void *pool_aligned_realloc(MemoryPool* mPool,
void *ptr,
size_t size,
size_t alignment);
192 bool pool_reset(MemoryPool* memPool);
193 bool pool_free(MemoryPool *memPool,
void *
object);
194 MemoryPool *pool_identify(
void *
object);
195 size_t pool_msize(MemoryPool *memPool,
void *
object);
202 #ifndef __TBB_NO_IMPLICIT_LINKAGE
203 #define __TBB_NO_IMPLICIT_LINKAGE 1
205 #undef __TBB_NO_IMPLICIT_LINKAGE
210 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
214 #if __TBB_CPP17_MEMORY_RESOURCE_PRESENT
215 #include <memory_resource>
220 #if _MSC_VER && !defined(__INTEL_COMPILER)
222 #pragma warning (push)
223 #pragma warning (disable: 4100)
229 #if TBB_USE_EXCEPTIONS
248 class scalable_allocator {
251 typedef value_type* pointer;
252 typedef const value_type* const_pointer;
253 typedef value_type& reference;
254 typedef const value_type& const_reference;
255 typedef size_t size_type;
256 typedef ptrdiff_t difference_type;
257 template<
class U>
struct rebind {
258 typedef scalable_allocator<U> other;
261 scalable_allocator() throw() {}
262 scalable_allocator(
const scalable_allocator& )
throw() {}
263 template<
typename U> scalable_allocator(
const scalable_allocator<U>&)
throw() {}
265 pointer
address(reference x)
const {
return &x;}
266 const_pointer
address(const_reference x)
const {
return &x;}
269 pointer allocate( size_type n,
const void* =0 ) {
270 pointer
p =
static_cast<pointer
>(
scalable_malloc( n *
sizeof(value_type) ) );
277 void deallocate( pointer
p, size_type ) {
282 size_type max_size()
const throw() {
283 size_type absolutemax =
static_cast<size_type
>(-1) /
sizeof (value_type);
284 return (absolutemax > 0 ? absolutemax : 1);
286 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
287 template<
typename U,
typename... Args>
288 void construct(U *
p, Args&&... args)
289 { ::new((
void *)
p) U(std::forward<Args>(args)...); }
291 #if __TBB_CPP11_RVALUE_REF_PRESENT
292 void construct( pointer
p, value_type&&
value ) { ::new((
void*)(
p)) value_type(
std::move(
value ) ); }
294 void construct( pointer
p,
const value_type&
value ) {::new((
void*)(
p)) value_type(
value);}
296 void destroy( pointer
p ) {
p->~value_type();}
299 #if _MSC_VER && !defined(__INTEL_COMPILER)
300 #pragma warning (pop)
306 class scalable_allocator<
void> {
308 typedef void* pointer;
309 typedef const void* const_pointer;
310 typedef void value_type;
311 template<
class U>
struct rebind {
312 typedef scalable_allocator<U> other;
316 template<
typename T,
typename U>
317 inline bool operator==(
const scalable_allocator<T>&,
const scalable_allocator<U>& ) {
return true;}
319 template<
typename T,
typename U>
320 inline bool operator!=(
const scalable_allocator<T>&,
const scalable_allocator<U>& ) {
return false;}
322 #if __TBB_CPP17_MEMORY_RESOURCE_PRESENT
328 class scalable_resource_impl :
public std::pmr::memory_resource {
330 void* do_allocate(
size_t bytes,
size_t alignment)
override {
338 void do_deallocate(
void* ptr,
size_t ,
size_t )
override {
344 bool do_is_equal(
const std::pmr::memory_resource& other)
const noexcept
override {
345 return this == &other ||
346 #if __TBB_USE_OPTIONAL_RTTI
347 dynamic_cast<const scalable_resource_impl*
>(&other) != NULL;
357 inline std::pmr::memory_resource* scalable_memory_resource() noexcept {
358 static tbb::internal::scalable_resource_impl scalable_res;
359 return &scalable_res;
367 #if (__TBB_BUILD || __TBBMALLOC_BUILD) && !defined(__TBBMALLOC_NO_IMPLICIT_LINKAGE)
368 #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
371 #if !__TBBMALLOC_NO_IMPLICIT_LINKAGE
373 #pragma comment(lib, "tbbmalloc_debug.lib")
375 #pragma comment(lib, "tbbmalloc.lib")
384 #if !defined(__cplusplus) && __ICC==1100
385 #pragma warning (pop)