12 #ifndef THRILL_MEM_ALLOCATOR_BASE_HEADER 13 #define THRILL_MEM_ALLOCATOR_BASE_HEADER 27 #include <type_traits> 36 template <
typename Type, Manager& manager_>
39 static constexpr
bool debug =
false;
64 template <
typename OtherType>
68 #if !defined(_MSC_VER) 81 throw std::bad_alloc();
83 const size_t size = n *
sizeof(
Type);
87 printf(
"allocate() n=%zu sizeof(T)=%zu total=%zu\n",
88 n,
sizeof(
Type), manager_.total());
96 std::new_handler nh = std::get_new_handler();
98 throw std::bad_alloc();
109 manager_.subtract(n *
sizeof(
Type));
112 printf(
"deallocate() n=%zu sizeof(T)=%zu total=%zu\n",
113 n,
sizeof(
Type), manager_.total());
120 template <
typename Other>
126 template <
typename Other>
132 template <Manager& manager_>
140 template <
typename U>
151 template <
typename Type>
155 template <
typename T,
typename... Args>
159 allocator.
construct(value, std::forward<Args>(args) ...);
164 template <
typename T>
180 char, std::char_traits<char>, BypassAllocator<char> >;
183 template <
typename T>
187 template <
typename T>
188 using by_deque = std::deque<T, BypassAllocator<T> >;
192 return tlx::ssnprintf_generic<by_string>(4 *
sizeof(int),
"%d", val);
197 return tlx::ssnprintf_generic<by_string>(4 *
sizeof(int),
"%u", val);
202 return tlx::ssnprintf_generic<by_string>(4 *
sizeof(long),
"%ld", val);
207 return tlx::ssnprintf_generic<by_string>(4 *
sizeof(long),
"%lu", val);
212 return tlx::ssnprintf_generic<by_string>(4 *
sizeof(
long long),
"%lld", val);
217 return tlx::ssnprintf_generic<by_string>(4 *
sizeof(
long long),
"%llu", val);
223 #endif // !THRILL_MEM_ALLOCATOR_BASE_HEADER
FixedAllocator() noexcept=default
default constructor
void destroy(pointer p) const noexcept
Destroys in-place the object pointed by p.
bool operator==(const FixedAllocator< Other, manager_ > &) const noexcept
Compare to another allocator of same type.
std::deque< T, BypassAllocator< T > > by_deque
deque without malloc tracking
pointer allocate(size_type n, const void *=nullptr)
static constexpr bool debug
T * by_new(Args &&... args)
operator new with our Allocator
Manager g_bypass_manager
global bypass memory manager
void bypass_free(void *ptr, size_t size) noexcept
bypass malloc tracker and access free() directly
Return allocator for different type.
FixedAllocator(const FixedAllocator< OtherType, manager_ > &) noexcept
copy-constructor from a rebound allocator
static by_string to_string(int val)
convert to string
void construct(pointer p, const_reference value)
Constructs an element object on the location pointed by p.
std::ptrdiff_t difference_type
void * bypass_malloc(size_t size) noexcept
bypass malloc tracker and access malloc() directly
std::basic_stringbuf< char, std::char_traits< char >, BypassAllocator< char > > by_stringbuf
stringbuf without malloc tracking
const Type & const_reference
size_type max_size() const noexcept
Maximum size possible to allocate.
std::true_type is_always_equal
C++11 type flag.
void deallocate(pointer p, size_type n) const noexcept
const void * const_pointer
const Type * const_pointer
Object shared by allocators and other classes to track memory allocations.
std::basic_string< char, std::char_traits< char >, BypassAllocator< char > > by_string
string without malloc tracking
std::vector< T, BypassAllocator< T > > by_vector
vector without malloc tracking
bool operator!=(const FixedAllocator< Other, manager_ > &) const noexcept
Compare to another allocator of same type.
FixedAllocator & operator=(FixedAllocator &) noexcept=default
copy-assignment operator: default
void by_delete(T *value)
operator delete with our Allocator