Go to the documentation of this file.
29 #ifndef CASA_CONTAINERS_ALLOCATOR_H_
30 #define CASA_CONTAINERS_ALLOCATOR_H_
32 #include <casacore/casa/config.h>
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/Utilities/DataType.h>
40 #include <type_traits>
44 #ifndef CASA_DEFAULT_ALIGNMENT
45 # define CASA_DEFAULT_ALIGNMENT (32UL) // AVX/AVX2 alignment
79 template<
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
92 template<
typename TOther>
103 template<
typename TOther>
111 if (elements > this->max_size()) {
112 throw std::bad_alloc();
115 int result = posix_memalign(&memptr, ALIGNMENT,
sizeof(T) * elements);
117 throw std::bad_alloc();
119 return static_cast<pointer>(memptr);
127 template<
typename T,
size_t ALIGNMENT>
133 template<
typename T,
size_t ALIGNMENT>
150 template<
typename TOther>
161 template<
typename TOther>
169 if (elements > this->max_size()) {
170 throw std::bad_alloc();
172 return new T[elements];
178 template<
typename U,
typename... Args>
209 template<
typename T>
class Array;
210 template<
typename T>
class Block;
215 template<
typename T>
friend class Array;
216 template<
typename T>
friend class Block;
218 template<
typename T2>
220 typedef typename std::allocator<T2>::size_type
size_type;
221 typedef typename std::allocator<T2>::pointer
pointer;
236 template<
typename Allocator>
243 return allocator.allocate(elements, ptr);
252 for (i = 0; i < n; ++i) {
264 for (i = 0; i < n; ++i) {
265 allocator.construct(&ptr[i], initial_value);
275 for (i = 0; i < n; ++i) {
294 return typeid(Allocator);
302 template<
typename Allocator>
304 return get_allocator_raw<Allocator>();
307 template<
typename Allocator>
329 template<
typename Allocator>
345 template<
typename T,
typename Sub>
355 return Allocator_private::get_allocator<typename facade_type::type>();
379 template<
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
388 template<
typename T,
size_t ALIGNMENT>
casacore_allocator(const casacore_allocator &other) noexcept
constexpr ArrayInitPolicy(bool v)
~new_del_allocator() noexcept
void construct(U *ptr, U &value)
virtual Allocator_private::BulkAllocator< T > * getAllocator() const override
virtual const std::type_info & allocator_typeid() const override
virtual void deallocate(pointer ptr, size_type size) override
static Allocator allocator
Super::reference reference
Allocator::const_pointer const_pointer
Bool operator!=(ArrayInitPolicy const &other)
std11_allocator< T > Super
static AlignedAllocator< T, ALIGNMENT > value
an instance of this allocator.
bool operator!=(const casacore_allocator< T, ALIGNMENT > &, const casacore_allocator< T, ALIGNMENT > &)
Allocator::pointer pointer
Super::const_reference const_reference
Super::const_pointer const_pointer
virtual Allocator_private::BulkAllocator< T > * getAllocator() const =0
virtual pointer allocate(size_type elements, const void *ptr=0) override
virtual void destroy(pointer ptr, size_type n) override
Super::const_pointer const_pointer
virtual void construct(pointer ptr, size_type n, const_pointer src)=0
void construct(U *, Args &&...)
Super::const_reference const_reference
Allocator::value_type value_type
A global enum used by some Array/Block constructors.
pointer allocate(size_type elements, const void *=0)
Super::size_type size_type
Bool operator==(ArrayInitPolicy const &other)
virtual void construct(pointer ptr, size_type n, value_type const &initial_value) override
static NewDelAllocator< T > value
an instance of this allocator.
new_del_allocator< TOther > other
bool operator==(const casacore_allocator< T, ALIGNMENT > &, const casacore_allocator< T, ALIGNMENT > &)
casacore_allocator(const casacore_allocator< TOther > &) noexcept
std11_allocator< T > Super
virtual void deallocate(pointer ptr, size_type size)=0
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
virtual void destroy(pointer ptr, size_type n)=0
casacore_allocator< TOther > other
Super::value_type value_type
void construct(U *ptr, U const &value)
virtual const std::type_info & allocator_typeid() const =0
new_del_allocator< T > type
Super::value_type value_type
static BulkAllocator< typename Allocator::value_type > * get_allocator()
std::allocator< T2 >::size_type size_type
AlignedAllocator< T >::type type
AllocSpec(BulkAllocator< T > *alloc)
An allocator which allocates aligned memory.
void deallocate(pointer ptr, size_type)
this file contains all the compiler specific defines
static BulkAllocatorImpl< Allocator > * get_allocator_raw()
void deallocate(pointer ptr, size_type)
std::allocator< T2 >::pointer pointer
pointer allocate(size_type elements, const void *=0)
std::allocator< T2 >::value_type value_type
std::allocator< T > std11_allocator
An aligned allocator with the default alignment.
static constexpr ArrayInitPolicy INIT
Initialize all elements in the array with the default value.
Super::size_type size_type
virtual ~BulkAllocatorImpl() override
static constexpr size_t alignment
virtual pointer allocate(size_type elements, const void *ptr=0)=0
template <class T, class U> class vector;
BulkAllocator< T > * allocator
void construct(U *ptr, U &&value)
~casacore_allocator() noexcept
bool Bool
Define the standard types used by Casacore.
casacore_allocator< T, ALIGNMENT > type
static DefaultAllocator< T > value
an instance of this allocator.
new_del_allocator(const new_del_allocator< TOther > &) noexcept
static const AllocSpec< T > value
new_del_allocator(const new_del_allocator &other) noexcept
static constexpr ArrayInitPolicy NO_INIT
Don't initialize elements in the array.
Super::difference_type difference_type
virtual void construct(pointer ptr, size_type n, const_pointer src) override
virtual ~AbstractAllocator()
An allocator behaves like operator new[]/delete[].
std::allocator< T2 >::const_pointer const_pointer
Super::reference reference
Super::difference_type difference_type
new_del_allocator() noexcept
virtual void construct(pointer ptr, size_type n) override
Allocator::size_type size_type