6 #ifndef PIVX_SUPPORT_ALLOCATORS_MT_POOLED_SECURE_H
7 #define PIVX_SUPPORT_ALLOCATORS_MT_POOLED_SECURE_H
21 typedef std::allocator<T>
base;
34 nrequested_size +=
sizeof(size_t);
36 size_t pools_count = std::thread::hardware_concurrency();
37 pools.resize(pools_count);
38 for (
size_t i = 0; i < pools_count; i++) {
39 pools[i] = std::make_unique<internal_pool>(nrequested_size, nnext_size, nmax_size);
47 std::lock_guard<std::mutex> lock(
pools[bucket]->mutex);
48 uint8_t* ptr =
pools[bucket]->allocate(n *
sizeof(
T) +
sizeof(
size_t));
49 *(
size_t*)ptr = bucket;
50 return static_cast<T*
>(ptr +
sizeof(size_t));
58 uint8_t* ptr = (uint8_t*)p -
sizeof(
size_t);
59 size_t bucket = *(
size_t*)ptr;
60 std::lock_guard<std::mutex> lock(
pools[bucket]->mutex);
61 pools[bucket]->deallocate(ptr, n *
sizeof(
T));
67 size_t x = std::hash<std::thread::id>{}(std::this_thread::get_id());
68 return x %
pools.size();
82 std::vector<std::unique_ptr<internal_pool>>
pools;
#define T(expected, seed, data)
internal_pool(size_type nrequested_size, size_type nnext_size, size_type nmax_size)
base::const_reference const_reference
base::const_pointer const_pointer
void deallocate(T *p, std::size_t n)
base::value_type value_type
std::vector< std::unique_ptr< internal_pool > > pools
~mt_pooled_secure_allocator()
mt_pooled_secure_allocator(size_type nrequested_size=32, size_type nnext_size=32, size_type nmax_size=0)
base::reference reference
base::size_type size_type
base::difference_type difference_type
T * allocate(std::size_t n, const void *hint=0)
base::size_type size_type