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> 42 #ifndef CASA_DEFAULT_ALIGNMENT 43 # define CASA_DEFAULT_ALIGNMENT (32UL) // AVX/AVX2 alignment 77 template<
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
88 static constexpr
size_t alignment = ALIGNMENT;
90 template<
typename TOther>
101 template<
typename TOther>
108 pointer
allocate(size_type elements,
const void* = 0) {
109 if (elements > this->max_size()) {
110 throw std::bad_alloc();
113 int result = posix_memalign(&memptr, ALIGNMENT,
sizeof(T) * elements);
115 throw std::bad_alloc();
117 return static_cast<pointer
>(memptr);
125 template<
typename T,
size_t ALIGNMENT>
131 template<
typename T,
size_t ALIGNMENT>
148 template<
typename TOther>
159 template<
typename TOther>
166 pointer
allocate(size_type elements,
const void* = 0) {
167 if (elements > this->max_size()) {
168 throw std::bad_alloc();
170 return new T[elements];
176 template<
typename U,
typename... Args>
207 template<
typename T>
class Array;
208 template<
typename T>
class Block;
213 template<
typename T>
friend class Array;
214 template<
typename T>
friend class Block;
216 template<
typename T2>
218 typedef typename std::allocator<T2>::size_type
size_type;
219 typedef typename std::allocator<T2>::pointer
pointer;
223 virtual pointer allocate(size_type elements,
const void*ptr = 0) = 0;
224 virtual void deallocate(pointer ptr, size_type size) = 0;
226 virtual void construct(pointer ptr, size_type n, const_pointer src) = 0;
227 virtual void construct(pointer ptr, size_type n, value_type
const &initial_value) = 0;
228 virtual void construct(pointer ptr, size_type n) = 0;
229 virtual void destroy(pointer ptr, size_type n) = 0;
230 virtual std::type_info
const &allocator_typeid()
const = 0;
234 template<
typename Allocator>
240 virtual pointer
allocate(size_type elements,
const void *ptr = 0) {
241 return allocator.allocate(elements, ptr);
244 allocator.deallocate(ptr, size);
247 virtual void construct(pointer ptr, size_type n, const_pointer src) {
250 for (i = 0; i < n; ++i) {
251 allocator.construct(&ptr[i], src[i]);
259 value_type
const &initial_value) {
262 for (i = 0; i < n; ++i) {
263 allocator.construct(&ptr[i], initial_value);
273 for (i = 0; i < n; ++i) {
274 allocator.construct(&ptr[i]);
281 virtual void destroy(pointer ptr, size_type n) {
282 for (size_type i = n; i > 0;) {
285 allocator.destroy(&ptr[i]);
292 return typeid(Allocator);
300 template<
typename Allocator>
302 return get_allocator_raw<Allocator>();
304 template<
typename Allocator>
307 get_allocator_raw<Allocator>();
311 template<
typename Allocator>
341 template<
typename Allocator>
344 template<
typename Allocator>
360 template<
typename T,
typename Sub>
370 return Allocator_private::get_allocator<typename facade_type::type>();
394 template<
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
403 template<
typename T,
size_t ALIGNMENT>
std::allocator< T2 >::pointer pointer
AlignedAllocator< T >::type type
std::allocator< T2 >::const_pointer const_pointer
virtual void destroy(pointer ptr, size_type n)
void construct(U *ptr, U const &value)
Super::const_reference const_reference
An allocator which allocates aligned memory.
Super::const_pointer const_pointer
static NewDelAllocator< T > value
an instance of this allocator.
std::allocator< T > std11_allocator
std::allocator< T2 >::size_type size_type
An aligned allocator with the default alignment.
void deallocate(pointer ptr, size_type)
~new_del_allocator() noexcept
virtual std::type_info const & allocator_typeid() const
virtual Allocator_private::BulkAllocator< T > * getAllocator() const
virtual void construct(pointer ptr, size_type n, const_pointer src)
static AllocSpec< T > const value
Super::difference_type difference_type
Allocator::const_pointer const_pointer
virtual ~BulkAllocatorImpl()
Allocator::size_type size_type
new_del_allocator< TOther > other
new_del_allocator() noexcept
pointer allocate(size_type elements, const void *=0)
A global enum used by some Array/Block constructors.
static AlignedAllocator< T, ALIGNMENT > value
an instance of this allocator.
Super::size_type size_type
static DefaultAllocator< T > value
an instance of this allocator.
new_del_allocator< T > type
casacore_allocator< TOther > other
new_del_allocator(const new_del_allocator &other) noexcept
Super::value_type value_type
casacore_allocator< T, ALIGNMENT > type
new_del_allocator(const new_del_allocator< TOther > &) noexcept
Super::const_pointer const_pointer
virtual void construct(pointer ptr, size_type n, value_type const &initial_value)
virtual void deallocate(pointer ptr, size_type size)
Super::const_reference const_reference
Allocator::value_type value_type
BulkAllocatorInitializer()
~casacore_allocator() noexcept
void deallocate(pointer ptr, size_type)
void construct(U *ptr, U &&value)
BulkAllocator< T > * allocator
constexpr ArrayInitPolicy(bool v)
bool Bool
Define the standard types used by Casacore.
static BulkAllocatorImpl< Allocator > * get_allocator_raw()
virtual pointer allocate(size_type elements, const void *ptr=0)
virtual void construct(pointer ptr, size_type n)
template <class T, class U> class vector;
std::allocator< T2 >::value_type value_type
Bool operator!=(ArrayInitPolicy const &other)
pointer allocate(size_type elements, const void *=0)
static Allocator allocator
void construct(U *, Args &&...)
void construct(U *ptr, U &value)
Bool operator==(ArrayInitPolicy const &other)
AllocSpec(BulkAllocator< T > *alloc)
Super::value_type value_type
casacore_allocator(const casacore_allocator &other) noexcept
Super::reference reference
virtual ~AbstractAllocator()
static BulkAllocator< typename Allocator::value_type > * get_allocator()
An allocator behaves like operator new[]/delete[].
Super::reference reference
casacore_allocator(const casacore_allocator< TOther > &) noexcept
std11_allocator< T > Super
Super::size_type size_type
Allocator::pointer pointer
this file contains all the compiler specific defines
Super::difference_type difference_type
std11_allocator< T > Super
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
static BulkAllocatorInitializer< Allocator > instance