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 #if __cplusplus < 201103L && ! defined(noexcept) 43 # define noexcept throw() 44 # define CASA_UNDEF_noexcept 47 #ifndef CASA_DEFAULT_ALIGNMENT 48 # define CASA_DEFAULT_ALIGNMENT (32UL) // AVX/AVX2 alignment 74 #if __cplusplus < 201103L 77 typedef std::allocator<T>
Super;
86 template<
typename TOther>
91 ::new(static_cast<void *>(ptr)) T();
94 Super::construct(ptr, val);
115 template<
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
125 #if __cplusplus < 201103L 126 enum {alignment = ALIGNMENT};
128 static constexpr
size_t alignment = ALIGNMENT;
131 template<
typename TOther>
142 template<
typename TOther>
149 pointer
allocate(size_type elements,
const void* = 0) {
150 if (elements > this->max_size()) {
151 throw std::bad_alloc();
154 int result = posix_memalign(&memptr, ALIGNMENT,
sizeof(T) * elements);
156 throw std::bad_alloc();
158 return static_cast<pointer
>(memptr);
166 template<
typename T,
size_t ALIGNMENT>
172 template<
typename T,
size_t ALIGNMENT>
189 template<
typename TOther>
200 template<
typename TOther>
207 pointer
allocate(size_type elements,
const void* = 0) {
208 if (elements > this->max_size()) {
209 throw std::bad_alloc();
211 return new T[elements];
217 #if __cplusplus < 201103L 223 template<
typename U,
typename... Args>
224 void construct(U *, Args&&... ) {}
226 void construct(U *ptr, U &&
value) {
230 void construct(U *ptr, U &
value) {
234 void construct(U *ptr, U
const &value) {
255 template<
typename T>
class Array;
256 template<
typename T>
class Block;
261 template<
typename T>
friend class Array;
262 template<
typename T>
friend class Block;
264 template<
typename T2>
266 typedef typename std::allocator<T2>::size_type
size_type;
267 typedef typename std::allocator<T2>::pointer
pointer;
271 virtual pointer allocate(size_type elements,
const void*ptr = 0) = 0;
272 virtual void deallocate(pointer ptr, size_type size) = 0;
274 virtual void construct(pointer ptr, size_type n, const_pointer src) = 0;
275 virtual void construct(pointer ptr, size_type n, value_type
const &initial_value) = 0;
276 virtual void construct(pointer ptr, size_type n) = 0;
277 virtual void destroy(pointer ptr, size_type n) = 0;
278 virtual std::type_info
const &allocator_typeid()
const = 0;
282 template<
typename Allocator>
288 virtual pointer
allocate(size_type elements,
const void *ptr = 0) {
289 return allocator.allocate(elements, ptr);
292 allocator.deallocate(ptr, size);
295 virtual void construct(pointer ptr, size_type n, const_pointer src) {
298 for (i = 0; i < n; ++i) {
299 allocator.construct(&ptr[i], src[i]);
307 value_type
const &initial_value) {
310 for (i = 0; i < n; ++i) {
311 allocator.construct(&ptr[i], initial_value);
321 for (i = 0; i < n; ++i) {
322 allocator.construct(&ptr[i]);
329 virtual void destroy(pointer ptr, size_type n) {
330 for (size_type i = n; i > 0;) {
333 allocator.destroy(&ptr[i]);
340 return typeid(Allocator);
348 template<
typename Allocator>
350 return get_allocator_raw<Allocator>();
352 template<
typename Allocator>
355 get_allocator_raw<Allocator>();
359 template<
typename Allocator>
389 template<
typename Allocator>
392 template<
typename Allocator>
408 template<
typename T,
typename Sub>
418 return Allocator_private::get_allocator<typename facade_type::type>();
442 template<
typename T,
size_t ALIGNMENT = CASA_DEFAULT_ALIGNMENT>
451 template<
typename T,
size_t ALIGNMENT>
479 #if defined(CASA_UNDEF_noexcept) 481 # undef CASA_UNDEF_noexcept
std::allocator< T2 >::pointer pointer
Super::const_pointer const_pointer
AlignedAllocator< T >::type type
std::allocator< T2 >::const_pointer const_pointer
virtual void destroy(pointer ptr, size_type n)
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.
static ArrayInitPolicy const NO_INIT
Don't initialize elements in the array.
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 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.
std11_allocator< TOther > other
new_del_allocator< T > type
casacore_allocator< TOther > other
Super::value_type value_type
void construct(pointer ptr, const_reference value)
std::allocator< T > Super
new_del_allocator(const new_del_allocator &other) noexcept
Super::value_type value_type
void construct(pointer ptr, const_reference val)
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)
static ArrayInitPolicy const INIT
Initialize all elements in the array with the default value.
virtual void deallocate(pointer ptr, size_type size)
Super::const_reference const_reference
Allocator::value_type value_type
BulkAllocatorInitializer()
~casacore_allocator() noexcept
virtual std::type_info const & allocator_typeid() const
void deallocate(pointer ptr, size_type)
BulkAllocator< T > * allocator
bool Bool
Define the standard types used by Casacore.
static BulkAllocatorImpl< Allocator > * get_allocator_raw()
void construct(pointer ptr)
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
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::difference_type difference_type
Super::size_type size_type
Allocator::pointer pointer
Super::size_type size_type
virtual Allocator_private::BulkAllocator< T > * getAllocator() const
Super::reference reference
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
Super::const_reference const_reference