17 #ifndef THRILL_MEM_POOL_HEADER 18 #define THRILL_MEM_POOL_HEADER 29 #include <type_traits> 76 static constexpr
bool debug =
false;
84 explicit Pool(
size_t default_arena_size = 16384) noexcept;
89 Pool& operator = (const
Pool&) = delete;
103 template <typename
Type, typename... Args>
105 Type* t =
reinterpret_cast<Type*
>(
allocate(
sizeof(Type)));
106 ::new (t)
Type(std::forward<Args>(args) ...);
111 template <
typename Type>
118 void print(
bool debug =
true);
172 std::vector<std::pair<void*, size_t> >
allocs_;
193 template <
typename Type>
209 template <
typename U>
220 template <
typename OtherType>
222 : pool_(other.pool_) { }
236 return static_cast<Type*
>(pool_->allocate(n *
sizeof(
Type)));
250 template <
typename Other>
252 return (pool_ == other.pool_);
256 template <
typename Other>
258 return (pool_ != other.pool_);
265 template <
typename Type, Pool& (* pool_)()>
281 template <
typename U>
291 template <
typename OtherType>
306 return static_cast<Type*
>(pool_().allocate(n *
sizeof(
Type)));
316 template <
typename Other>
322 template <
typename Other>
329 template <
typename Type>
333 template <
typename T>
338 void operator () (
T* ptr)
const noexcept {
344 template <
typename T>
348 template <
typename T,
typename... Args>
351 GPool().
make<
T>(std::forward<Args>(args) ...));
362 char, std::char_traits<char>, mem::GPoolAllocator<char> >;
367 #endif // !THRILL_MEM_POOL_HEADER size_type max_size() const noexcept
maximum size possible to allocate
size_t max_size() const noexcept
maximum size possible to allocate
std::ptrdiff_t difference_type
Return allocator for different type.
std::false_type is_always_equal
C++11 type flag.
ObjectPool * object_32_
object areas for small fixed size items
pointer allocate(size_type n, const void *=nullptr)
std::vector< std::pair< void *, size_t > > allocs_
array of allocations for checking
Type * make(Args &&... args)
std::unique_ptr< T, GPoolDeleter< T > > safe_unique_ptr
unique_ptr with memory from mem::g_pool.
size_t bytes_per_arena(size_t arena_size)
calculate maximum bytes fitting into an Arena with given size.
void self_verify()
Print out structure of the arenas.
static constexpr bool debug_check_pairing
debug flag to check pairing of allocate()/deallocate() client calls
void deallocate(pointer p, size_type n) const noexcept
const Type & const_reference
size_type max_size() const noexcept
maximum size possible to allocate
void destroy(Type *t)
Destroy and deallocate a single item of given Type.
A simple memory allocation manager.
void * ArenaFindFree(Arena *curr_arena, size_t bin, size_t n, size_t bytes)
find free area inside an Arena
Arena * AllocateFreeArena(size_t arena_size, bool die_on_failure=true)
allocate a new Arena blob
size_t min_free_
minimum amount of spare memory to keep in the Pool.
void * allocate(size_t bytes)
allocate a continuous segment of n bytes in the arenas
std::basic_ostringstream< char, std::char_traits< char >, mem::GPoolAllocator< char > > safe_ostringstream
Return allocator for different type.
Pool & GPool()
singleton instance of global pool for I/O data structures
std::true_type is_always_equal
C++11 type flag.
deleter for unique_ptr with memory from mem::g_pool.
void print(bool debug=true)
Print out structure of the arenas.
Pool(size_t default_arena_size=16384) noexcept
construct with base allocator
std::basic_string< char, std::char_traits< char >, mem::GPoolAllocator< char > > safe_string
void IntDeallocateAll()
deallocate all Arenas
bool operator==(const uint_pair &b) const
equality checking operator
static const size_t bytes
number of bytes in uint_pair
pointer allocate(size_type n, const void *=nullptr)
const Type * const_pointer
PoolAllocator(Pool &pool) noexcept
construct PoolAllocator with Pool object
std::ptrdiff_t difference_type
size_t free_
number of free slots in all arenas
const Type * const_pointer
const Type & const_reference
void DeallocateAll()
deallocate all Arenas
Pool & operator=(const Pool &)=delete
non-copyable: delete assignment operator
PoolAllocator(const PoolAllocator< OtherType > &other) noexcept
copy-constructor from a rebound allocator
void deallocate(pointer p, size_type n) const noexcept
static constexpr bool debug
size_t size_
overall number of used slots
safe_unique_ptr< T > safe_make_unique(Args &&... args)
make_unique with Manager tracking
Arena * arena_bin_[num_bins+1]
FixedPoolAllocator(const FixedPoolAllocator< OtherType, pool_ > &) noexcept
copy-constructor from a rebound allocator
static constexpr size_t check_limit
size_t default_arena_size_
size of default Arena allocation
void deallocate(void *ptr, size_t bytes)
static const size_t num_bins
number of bins
bool operator!=(const uint_pair &b) const
inequality checking operator
static constexpr bool debug_verify