12 #ifndef THRILL_MEM_ALLOCATOR_HEADER 13 #define THRILL_MEM_ALLOCATOR_HEADER 24 #include <type_traits> 30 template <
typename Type>
33 static constexpr
bool debug =
false;
59 template <
typename OtherType>
71 throw std::bad_alloc();
73 const size_t size = n *
sizeof(
Type);
77 printf(
"allocate() n=%zu sizeof(T)=%zu total=%zu\n",
86 std::new_handler nh = std::get_new_handler();
88 throw std::bad_alloc();
102 printf(
"deallocate() n=%zu sizeof(T)=%zu total=%zu\n",
114 template <
typename Other>
116 return (manager_ ==
other.manager_);
120 template <
typename Other>
122 return (manager_ !=
other.manager_);
137 template <
typename U>
148 template <
typename OtherType>
157 template <
typename Other>
159 return (manager_ ==
other.manager_);
163 template <
typename Other>
165 return (manager_ !=
other.manager_);
170 template <
typename T,
typename... Args>
174 allocator.
construct(value, std::forward<Args>(args) ...);
179 template <
typename T>
187 template <
typename T>
193 : allocator_(manager) { }
196 void operator () (
T* ptr)
const noexcept {
197 allocator_.destroy(ptr);
198 allocator_.deallocate(ptr, 1);
207 template <
typename T>
211 template <
typename T,
typename... Args>
214 mm_new<T>(manager, std::forward<Args>(args) ...),
219 using string = std::basic_string<
224 char, std::char_traits<char>, Allocator<char> >;
227 template <
typename T>
228 using vector = std::vector<T, Allocator<T> >;
231 template <
typename T>
232 using deque = std::deque<T, Allocator<T> >;
237 #endif // !THRILL_MEM_ALLOCATOR_HEADER
pointer allocate(size_type n, const void *=nullptr)
std::false_type is_always_equal
C++11 type flag.
bool operator==(const Allocator< Other > &other) const noexcept
Compare to another allocator of same type.
std::basic_stringbuf< char, std::char_traits< char >, Allocator< char > > stringbuf
stringbuf with Manager tracking
void destroy(pointer p) const noexcept
Destroys in-place the object pointed by p.
const void * const_pointer
bool operator!=(const Allocator< Other > &other) const noexcept
Compare to another allocator of same type.
Allocator(const Allocator< OtherType > &other) noexcept
copy-constructor from a rebound allocator
Allocator(Manager &manager) noexcept
Construct Allocator with Manager object.
std::ptrdiff_t difference_type
void deallocate(pointer p, size_type n) const noexcept
Deleter(Manager &manager) noexcept
constructor: need reference to Manager
Manager & add(size_t amount)
add memory consumption.
void bypass_free(void *ptr, size_t size) noexcept
bypass malloc tracker and access free() directly
Allocator & operator=(const Allocator &) noexcept=default
copy-assignment operator
void construct(pointer p, const_reference value)
Constructs an element object on the location pointed by p.
Manager & subtract(size_t amount)
subtract memory consumption.
void * bypass_malloc(size_t size) noexcept
bypass malloc tracker and access malloc() directly
static constexpr bool debug
Allocator(Manager &manager) noexcept
Construct Allocator with Manager object.
unique_ptr< T > make_unique(Manager &manager, Args &&... args)
make_unique with Manager tracking
const char * const_pointer
const char & const_reference
Allocator< T > allocator_
reference to Manager for freeing.
std::vector< T, Allocator< T > > vector
vector with Manager tracking
size_type max_size() const noexcept
Maximum size possible to allocate.
std::deque< T, Allocator< T > > deque
deque with Manager tracking
T * mm_new(Manager &manager, Args &&... args)
operator new with our Allocator
std::default_deleter with Manager tracking
size_t total() const
return total allocation (local value)
Object shared by allocators and other classes to track memory allocations.
std::false_type is_always_equal
C++11 type flag.
Allocator(const Allocator< OtherType > &other) noexcept
copy-constructor from a rebound allocator
std::unique_ptr< T, Deleter< T > > unique_ptr
unique_ptr with Manager tracking
void mm_delete(Manager &manager, T *value)
operator delete with our Allocator
Return allocator for different type.