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>
35 #include <casacore/casa/Arrays/ArrayFwd.h>
41 #include <type_traits>
45 #ifndef CASA_DEFAULT_ALIGNMENT
46 # define CASA_DEFAULT_ALIGNMENT (32UL)
80 template<
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
93 template<
typename TOther>
104 template<
typename TOther>
112 if (elements > this->max_size()) {
113 throw std::bad_alloc();
116 int result = posix_memalign(&memptr, ALIGNMENT,
sizeof(T) * elements);
118 throw std::bad_alloc();
120 return static_cast<pointer>(memptr);
128 template<
typename T,
size_t ALIGNMENT>
134 template<
typename T,
size_t ALIGNMENT>
151 template<
typename TOther>
162 template<
typename TOther>
170 if (elements > this->max_size()) {
171 throw std::bad_alloc();
173 return new T[elements];
179 template<
typename U,
typename... Args>
210 template<
typename T>
class Block;
215 template<
typename T>
friend class Block;
217 template<
typename T2>
219 typedef typename std::allocator<T2>::size_type
size_type;
220 typedef typename std::allocator<T2>::pointer
pointer;
235 template<
typename Allocator>
242 return allocator.allocate(elements, ptr);
251 for (i = 0; i < n; ++i) {
263 for (i = 0; i < n; ++i) {
264 allocator.construct(&ptr[i], initial_value);
274 for (i = 0; i < n; ++i) {
293 return typeid(Allocator);
301 template<
typename Allocator>
303 return get_allocator_raw<Allocator>();
306 template<
typename Allocator>
328 template<
typename Allocator>
338 friend class Array<T>;
339 friend class Block<T>;
344 template<
typename T,
typename Sub>
354 return Allocator_private::get_allocator<typename facade_type::type>();
378 template<
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
387 template<
typename T,
size_t ALIGNMENT>
virtual Allocator_private::BulkAllocator< T > * getAllocator() const =0
virtual ~AbstractAllocator()
An allocator which allocates aligned memory.
static AlignedAllocator< T, ALIGNMENT > value
an instance of this allocator.
casacore_allocator< T, ALIGNMENT > type
static BulkAllocator< typename Allocator::value_type > * get_allocator()
static BulkAllocatorImpl< Allocator > * get_allocator_raw()
Bool operator==(ArrayInitPolicy const &other)
constexpr ArrayInitPolicy(bool v)
Bool operator!=(ArrayInitPolicy const &other)
virtual Allocator_private::BulkAllocator< T > * getAllocator() const override
An aligned allocator with the default alignment.
static DefaultAllocator< T > value
an instance of this allocator.
AlignedAllocator< T >::type type
An allocator behaves like operator new[]/delete[].
static NewDelAllocator< T > value
an instance of this allocator.
new_del_allocator< T > type
this file contains all the compiler specific defines
bool operator==(const casacore_allocator< T, ALIGNMENT > &, const casacore_allocator< T, ALIGNMENT > &)
bool operator!=(const casacore_allocator< T, ALIGNMENT > &, const casacore_allocator< T, ALIGNMENT > &)
std::allocator< T > std11_allocator
bool Bool
Define the standard types used by Casacore.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
static AllocSpec< T > const value
AllocSpec(BulkAllocator< T > *alloc)
BulkAllocator< T > * allocator
Allocator::size_type size_type
virtual void construct(pointer ptr, size_type n, const_pointer src) override
virtual std::type_info const & allocator_typeid() const override
virtual void construct(pointer ptr, size_type n, value_type const &initial_value) override
virtual void construct(pointer ptr, size_type n) override
Allocator::pointer pointer
virtual void deallocate(pointer ptr, size_type size) override
Allocator::value_type value_type
static Allocator allocator
Allocator::const_pointer const_pointer
virtual void destroy(pointer ptr, size_type n) override
virtual pointer allocate(size_type elements, const void *ptr=0) override
virtual ~BulkAllocatorImpl() override
std::allocator< T2 >::size_type size_type
virtual std::type_info const & allocator_typeid() const =0
virtual pointer allocate(size_type elements, const void *ptr=0)=0
virtual void deallocate(pointer ptr, size_type size)=0
virtual void construct(pointer ptr, size_type n, value_type const &initial_value)=0
virtual void construct(pointer ptr, size_type n, const_pointer src)=0
std::allocator< T2 >::value_type value_type
std::allocator< T2 >::const_pointer const_pointer
virtual void construct(pointer ptr, size_type n)=0
virtual void destroy(pointer ptr, size_type n)=0
std::allocator< T2 >::pointer pointer
static constexpr ArrayInitPolicy NO_INIT
Don't initialize elements in the array.
static constexpr ArrayInitPolicy INIT
Initialize all elements in the array with the default value.
casacore_allocator< TOther > other
void deallocate(pointer ptr, size_type)
Super::reference reference
casacore_allocator(const casacore_allocator< TOther > &) noexcept
~casacore_allocator() noexcept
Super::difference_type difference_type
std11_allocator< T > Super
Super::size_type size_type
Super::const_pointer const_pointer
Super::const_reference const_reference
casacore_allocator(const casacore_allocator &other) noexcept
Super::value_type value_type
static constexpr size_t alignment
pointer allocate(size_type elements, const void *=0)
new_del_allocator< TOther > other
Super::const_pointer const_pointer
Super::size_type size_type
~new_del_allocator() noexcept
void construct(U *ptr, U &value)
new_del_allocator() noexcept
pointer allocate(size_type elements, const void *=0)
std11_allocator< T > Super
void construct(U *, Args &&...)
Super::value_type value_type
Super::reference reference
void deallocate(pointer ptr, size_type)
new_del_allocator(const new_del_allocator &other) noexcept
void construct(U *ptr, U const &value)
Super::difference_type difference_type
void construct(U *ptr, U &&value)
Super::const_reference const_reference
new_del_allocator(const new_del_allocator< TOther > &) noexcept