27#ifndef CASA_CONTAINERS_ALLOCATOR_H_
28#define CASA_CONTAINERS_ALLOCATOR_H_
30#include <casacore/casa/config.h>
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Utilities/DataType.h>
33#include <casacore/casa/Arrays/ArrayFwd.h>
44#ifndef CASA_DEFAULT_ALIGNMENT
45#define CASA_DEFAULT_ALIGNMENT (32UL)
76template <
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
89 template <
typename TOther>
97 template <typename TOther>
103 if (elements > std::allocator_traits<casacore_allocator>::max_size(*
this)) {
104 throw std::bad_alloc();
107 int result = posix_memalign(&memptr, ALIGNMENT,
sizeof(T) * elements);
109 throw std::bad_alloc();
111 return static_cast<pointer>(memptr);
117template <
typename T,
size_t ALIGNMENT>
123template <
typename T,
size_t ALIGNMENT>
140 template <
typename TOther>
148 template <
typename TOther>
154 if (elements > std::allocator_traits<new_del_allocator>::max_size(*
this)) {
155 throw std::bad_alloc();
157 return new T[elements];
161 template <
typename U,
typename... Args>
163 template <
typename U>
167 template <
typename U>
171 template <
typename U>
176 template <
typename U>
194 template <
typename T>
196 template <
typename T,
typename Sub>
198 template <
typename T>
201 template <
typename T2>
203 using size_type =
typename std::allocator<T2>::size_type;
219 template <
typename Allocator>
226 return allocator.allocate(elements, ptr);
235 for (i = 0; i < n; ++i) {
236 std::allocator_traits<Allocator>::construct(
allocator, &ptr[i], src[i]);
246 for (i = 0; i < n; ++i) {
247 std::allocator_traits<Allocator>::construct(
allocator, &ptr[i], initial_value);
257 for (i = 0; i < n; ++i) {
258 std::allocator_traits<Allocator>::construct(
allocator, &ptr[i]);
269 std::allocator_traits<Allocator>::destroy(
allocator, &ptr[i]);
275 virtual std::type_info
const &
allocator_typeid()
const override {
return typeid(Allocator); }
282 template <
typename Allocator>
287 template <
typename Allocator>
304 template <
typename T>
311template <
typename Allocator>
322 friend class Array<T>;
323 friend class Block<T>;
328template <
typename T,
typename Sub>
363template <
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
373template <
typename T,
size_t ALIGNMENT>
virtual Allocator_private::BulkAllocator< T > * getAllocator() const =0
virtual ~AbstractAllocator()
An allocator which allocates aligned memory.
static AlignedAllocator< T, CASA_DEFAULT_ALIGNMENT > value
casacore_allocator< T, ALIGNMENT > type
static BulkAllocator< typename Allocator::value_type > * get_allocator()
static BulkAllocatorImpl< Allocator > * get_allocator_raw()
friend class AbstractAllocator
friend class BaseAllocator
Bool operator==(ArrayInitPolicy const &other)
friend struct ArrayInitPolicies
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[].
new_del_allocator< T > type
static NewDelAllocator< T > value
an instance of this allocator.
bool operator==(const String &x, const String &y)
Global comparison operators.
For temporary backward namespace compatibility, use casa as alias for casacore.
T * storage()
If you really, really, need a "raw" pointer to the beginning of the storage area this will give it to...
bool Bool
Define the standard types used by Casacore.
bool operator!=(const String &x, const String &y)
NewDelAllocator< T > NewDelAllocator< T >::value
std::allocator< T > std11_allocator
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 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 std::type_info const & allocator_typeid() const override
virtual pointer allocate(size_type elements, const void *ptr=0) override
virtual ~BulkAllocatorImpl() override
virtual std::type_info const & allocator_typeid() const =0
typename std::allocator< T2 >::size_type size_type
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
virtual void construct(pointer ptr, size_type n)=0
typename std::allocator< T2 >::value_type value_type
virtual void destroy(pointer ptr, size_type n)=0
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)
typename Super::value_type value_type
const T & const_reference
casacore_allocator() noexcept=default
std11_allocator< T > Super
~casacore_allocator() noexcept=default
typename Super::size_type size_type
static constexpr size_t alignment
pointer allocate(size_type elements, const void *=0)
typename Super::difference_type difference_type
new_del_allocator< TOther > other
typename Super::size_type size_type
~new_del_allocator() noexcept
void construct(U *ptr, U &value)
new_del_allocator() noexcept
const T & const_reference
pointer allocate(size_type elements, const void *=0)
void construct(U *, Args &&...)
typename Super::difference_type difference_type
typename Super::value_type value_type
void deallocate(pointer ptr, size_type)
new_del_allocator(const new_del_allocator &other) noexcept
std11_allocator< T > Super
void construct(U *ptr, U const &value)
void construct(U *ptr, U &&value)
new_del_allocator(const new_del_allocator< TOther > &) noexcept