170:
public AbstractArrayBase
174 typedef typename ArrayTraits<T>::ConstReferenceType ConstReferenceType;
175 typedef typename ArrayTraits<T>::IsPODType IsPODType;
200 typedef std::reverse_iterator<iterator> reverse_iterator;
201 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
230 static constexpr Int64 typeSize() {
return static_cast<Int64
>(
sizeof(T)); }
231 AllocatedMemoryInfo _currentMemoryInfo()
const
233 return AllocatedMemoryInfo(m_ptr, m_md->size * typeSize(), m_md->capacity * typeSize());
248 _createRange(0, asize, view.
data());
263 void* pre_allocated_buffer =
nullptr)
275 _internalDeallocate();
279 if (options.allocator() != m_md->_allocator())
290 operator Span<const T>()
const
292 return Span<const T>(m_ptr, m_md->
size);
294 operator SmallSpan<const T>()
const
296 return SmallSpan<const T>(m_ptr, ARCCORE_CAST_SMALL_SIZE(
size()));
302 Integer size()
const {
return ARCCORE_CAST_SMALL_SIZE(m_md->size); }
314 bool empty()
const {
return m_md->size == 0; }
318 const T* ptr = m_ptr;
319 for (
Int64 i = 0, n = m_md->size; i < n; ++i) {
331 ARCCORE_CHECK_AT(i, m_md->size);
337 ARCCORE_CHECK_AT(i, m_md->size);
346 m_md->_setMemoryLocationHint(new_hint, m_ptr,
sizeof(T));
357 m_md->m_host_device_memory_location = location;
363 return m_md->m_host_device_memory_location;
375 return !(rhs == lhs);
378 friend bool operator==(
const AbstractArray<T>& rhs,
const Span<const T>& lhs)
380 return operator==(Span<const T>(rhs), lhs);
383 friend bool operator!=(
const AbstractArray<T>& rhs,
const Span<const T>& lhs)
385 return !(rhs == lhs);
388 friend bool operator==(
const Span<const T>& rhs,
const AbstractArray<T>& lhs)
390 return operator==(rhs, Span<const T>(lhs));
393 friend bool operator!=(
const Span<const T>& rhs,
const AbstractArray<T>& lhs)
395 return !(rhs == lhs);
398 friend std::ostream& operator<<(std::ostream& o,
const AbstractArray<T>& val)
400 o << Span<const T>(val);
406 using AbstractArrayBase::m_meta_data;
420 if (new_capacity <= m_md->
capacity) {
423 if (m_meta_data.is_collective_allocator) {
439 if (_isSharedNull()) {
440 if (new_capacity != 0 || m_meta_data.is_collective_allocator)
441 _internalAllocate(new_capacity, queue);
445 Int64 acapacity = new_capacity;
446 if (compute_capacity) {
447 acapacity = m_md->capacity;
449 while (new_capacity > acapacity)
450 acapacity = (acapacity == 0) ? 4 : (acapacity + 1 + acapacity / 2);
456 if (m_meta_data.is_collective_allocator) {
457 _internalReallocate(m_md->capacity, queue);
461 _internalReallocate(acapacity, queue);
464 void _internalReallocate(
Int64 new_capacity,
RunQueue* queue)
466 if constexpr (std::is_trivially_copyable_v<T>) {
469 _directReAllocate(new_capacity, queue);
470 bool update = (new_capacity < old_capacity) || (m_ptr != old_ptr);
477 ArrayMetaData* old_md = m_md;
478 AllocatedMemoryInfo old_mem_info = _currentMemoryInfo();
479 Int64 old_size = m_md->size;
480 _directAllocate(new_capacity, queue);
481 if (m_ptr != old_ptr) {
482 for (
Int64 i = 0; i < old_size; ++i) {
483 new (m_ptr + i) T(old_ptr[i]);
486 m_md->nb_ref = old_md->nb_ref;
487 m_md->_deallocate(old_mem_info, queue);
494 void _internalDeallocate(RunQueue* queue =
nullptr)
498 if (!_isSharedNull())
499 m_md->_deallocate(_currentMemoryInfo(), queue);
500 if (m_md->is_not_null)
501 _deallocateMetaData(m_md);
503 void _internalAllocate(
Int64 new_capacity, RunQueue* queue)
505 _directAllocate(new_capacity, queue);
510 void _copyFromMemory(
const T* source)
512 m_md->_copyFromMemory(m_ptr, source,
sizeof(T),
_nullRunQueue());
526 void* pre_allocated_buffer =
nullptr)
529 if (!wanted_allocator) {
530 wanted_allocator = ArrayMetaData::_defaultAllocator();
531 options.setAllocator(wanted_allocator);
534 m_md->allocation_options = options;
535 if (new_capacity > 0) {
536 if (!pre_allocated_buffer)
537 _allocateMP(new_capacity,
nullptr);
539 _setMPCast(pre_allocated_buffer);
550 _allocateMP(new_capacity, queue);
553 void _allocateMP(Int64 new_capacity, RunQueue* queue)
555 _setMPCast(m_md->_allocate(new_capacity, typeSize(), queue));
558 void _directReAllocate(
Int64 new_capacity, RunQueue* queue)
560 _setMPCast(m_md->_reallocate(_currentMemoryInfo(), new_capacity, typeSize(), queue));
565 void changeAllocator(
const MemoryAllocationOptions& options, RunQueue* queue)
567 _setMPCast(m_md->_changeAllocator(options, _currentMemoryInfo(), typeSize(), queue));
571 void changeAllocator(
const MemoryAllocationOptions& options)
573 _setMPCast(m_md->_changeAllocator(options, _currentMemoryInfo(), typeSize(),
_nullRunQueue()));
579 void printInfos(std::ostream& o)
581 o <<
" Infos: size=" << m_md->size <<
" capacity=" << m_md->capacity <<
'\n';
598 Int64 s = m_md->size;
599 if ((s + n) > m_md->capacity)
601 for (
Int64 i = 0; i < n; ++i)
602 new (m_ptr + s + i) T(val);
610 const T* ptr = val.
data();
611 Int64 s = m_md->size;
612 if ((s + n) > m_md->capacity)
614 _createRange(s, s + n, ptr);
621 if (m_md->nb_ref == 0) {
628 _destroyRange(0, m_md->
size, IsPODType());
630 void _destroyRange(Int64, Int64, TrueType)
634 void _destroyRange(
Int64 abegin,
Int64 aend, FalseType)
638 for (
Int64 i = abegin; i < aend; ++i)
641 void _createRangeDefault(
Int64,
Int64, TrueType)
644 void _createRangeDefault(
Int64 abegin,
Int64 aend, FalseType)
648 for (
Int64 i = abegin; i < aend; ++i)
651 void _createRange(
Int64 abegin,
Int64 aend, ConstReferenceType value, TrueType)
655 for (
Int64 i = abegin; i < aend; ++i)
658 void _createRange(
Int64 abegin,
Int64 aend, ConstReferenceType value, FalseType)
662 for (
Int64 i = abegin; i < aend; ++i)
663 new (m_ptr + i) T(value);
665 void _createRange(
Int64 abegin,
Int64 aend,
const T* values)
669 for (
Int64 i = abegin; i < aend; ++i) {
670 new (m_ptr + i) T(*values);
674 void _fill(ConstReferenceType value)
676 for (
Int64 i = 0, n =
size(); i < n; ++i)
679 void _clone(
const ThatClassType& orig_array)
681 Int64 that_size = orig_array.size();
683 m_md->size = that_size;
684 m_md->dim1_size = orig_array.m_md->dim1_size;
685 m_md->dim2_size = orig_array.m_md->dim2_size;
686 _createRange(0, that_size, orig_array.m_ptr);
688 template <
typename PodType>
689 void _resizeHelper(
Int64 s, PodType pod_type, RunQueue* queue)
693 if (s > m_md->size) {
695 this->_createRangeDefault(m_md->size, s, pod_type);
698 this->_destroyRange(s, m_md->size, pod_type);
699 if (m_meta_data.is_collective_allocator) {
705 void _resize(
Int64 s)
712 _resizeHelper(s,
TrueType{}, queue);
716 this->_destroyRange(0, m_md->
size, IsPODType());
724 if (s > m_md->size) {
726 this->_createRange(m_md->size, s, value, IsPODType());
729 this->_destroyRange(s, m_md->size, IsPODType());
730 if (m_meta_data.is_collective_allocator) {
736 void _copy(
const T* rhs_begin,
TrueType)
738 _copyFromMemory(rhs_begin);
740 void _copy(
const T* rhs_begin, FalseType)
742 for (Int64 i = 0, n = m_md->
size; i < n; ++i)
743 m_ptr[i] = rhs_begin[i];
745 void _copy(
const T* rhs_begin)
747 _copy(rhs_begin, IsPODType());
760 const T* rhs_begin = rhs.
data();
762 const Int64 current_size = m_md->size;
765 if (abegin >= rhs_begin && abegin < (rhs_begin + rhs_size))
766 ArrayMetaData::overlapError(abegin, m_md->size, rhs_begin, rhs_size);
768 if (rhs_size > current_size) {
771 this->_createRange(m_md->size, rhs_size, rhs_begin + current_size);
774 m_md->size = rhs_size;
777 this->_destroyRange(rhs_size, current_size, IsPODType{});
778 m_md->size = rhs_size;
790 void _move(ThatClassType& rhs) ARCCORE_NOEXCEPT
814 void _swap(ThatClassType& rhs) ARCCORE_NOEXCEPT
816 std::swap(m_ptr, rhs.m_ptr);
826 void _shrink(Int64 new_capacity)
831 if (new_capacity > this->
capacity())
833 if (new_capacity < 4)
851 if (asize > max_size)
853 asize =
static_cast<Integer>(max_size);
862 Span<const T> rhs_span(rhs);
863 if (rhs.allocator() == this->allocator()) {
877 void _setMP(TrueImpl* new_mp)
882 void _setMP2(TrueImpl* new_mp, ArrayMetaData* new_md)
888 if (!m_md->is_allocated_by_new)
894 return m_ptr ==
nullptr;
899 void _setToSharedNull()
902 m_meta_data = ArrayMetaData();
905 void _setMPCast(
void* p)
907 _setMP(
reinterpret_cast<TrueImpl*
>(p));