172:
public AbstractArrayBase
176 typedef typename ArrayTraits<T>::ConstReferenceType ConstReferenceType;
177 typedef typename ArrayTraits<T>::IsPODType IsPODType;
202 typedef std::reverse_iterator<iterator> reverse_iterator;
203 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
232 static constexpr Int64 typeSize() {
return static_cast<Int64
>(
sizeof(T)); }
233 AllocatedMemoryInfo _currentMemoryInfo()
const
235 return AllocatedMemoryInfo(m_ptr, m_md->size * typeSize(), m_md->capacity * typeSize());
250 _createRange(0, asize, view.
data());
265 void* pre_allocated_buffer =
nullptr)
267 _directFirstAllocateWithAllocator(acapacity, o, pre_allocated_buffer);
277 _internalDeallocate();
281 if (options.allocator() != m_md->_allocator())
282 _directFirstAllocateWithAllocator(0, options);
292 operator Span<const T>()
const
294 return Span<const T>(m_ptr, m_md->
size);
296 operator SmallSpan<const T>()
const
298 return SmallSpan<const T>(m_ptr, ARCCORE_CAST_SMALL_SIZE(
size()));
304 Integer size()
const {
return ARCCORE_CAST_SMALL_SIZE(m_md->size); }
316 bool empty()
const {
return m_md->size == 0; }
320 const T* ptr = m_ptr;
321 for (
Int64 i = 0, n = m_md->size; i < n; ++i) {
333 ARCCORE_CHECK_AT(i, m_md->size);
339 ARCCORE_CHECK_AT(i, m_md->size);
348 m_md->_setMemoryLocationHint(new_hint, m_ptr,
sizeof(T));
359 m_md->m_host_device_memory_location = location;
365 return m_md->m_host_device_memory_location;
377 return !(rhs == lhs);
380 friend bool operator==(
const AbstractArray<T>& rhs,
const Span<const T>& lhs)
382 return operator==(Span<const T>(rhs), lhs);
385 friend bool operator!=(
const AbstractArray<T>& rhs,
const Span<const T>& lhs)
387 return !(rhs == lhs);
390 friend bool operator==(
const Span<const T>& rhs,
const AbstractArray<T>& lhs)
392 return operator==(rhs, Span<const T>(lhs));
395 friend bool operator!=(
const Span<const T>& rhs,
const AbstractArray<T>& lhs)
397 return !(rhs == lhs);
400 friend std::ostream& operator<<(std::ostream& o,
const AbstractArray<T>& val)
402 o << Span<const T>(val);
408 using AbstractArrayBase::m_meta_data;
422 if (new_capacity <= m_md->
capacity) {
425 if (m_meta_data.is_collective_allocator) {
441 if (_isSharedNull()) {
442 if (new_capacity != 0 || m_meta_data.is_collective_allocator)
443 _internalAllocate(new_capacity, queue);
447 Int64 acapacity = new_capacity;
448 if (compute_capacity) {
449 acapacity = m_md->capacity;
451 while (new_capacity > acapacity)
452 acapacity = (acapacity == 0) ? 4 : (acapacity + 1 + acapacity / 2);
458 if (m_meta_data.is_collective_allocator) {
459 _internalReallocate(m_md->capacity, queue);
463 _internalReallocate(acapacity, queue);
466 void _internalReallocate(
Int64 new_capacity,
RunQueue* queue)
468 if constexpr (std::is_trivially_copyable_v<T>) {
471 _directReAllocate(new_capacity, queue);
472 bool update = (new_capacity < old_capacity) || (m_ptr != old_ptr);
479 ArrayMetaData* old_md = m_md;
480 AllocatedMemoryInfo old_mem_info = _currentMemoryInfo();
481 Int64 old_size = m_md->size;
482 _directAllocate(new_capacity, queue);
483 if (m_ptr != old_ptr) {
484 for (
Int64 i = 0; i < old_size; ++i) {
485 new (m_ptr + i) T(old_ptr[i]);
488 m_md->nb_ref = old_md->nb_ref;
489 m_md->_deallocate(old_mem_info, queue);
496 void _internalDeallocate(RunQueue* queue =
nullptr)
500 if (!_isSharedNull())
501 m_md->_deallocate(_currentMemoryInfo(), queue);
502 if (m_md->is_not_null)
503 _deallocateMetaData(m_md);
505 void _internalAllocate(
Int64 new_capacity, RunQueue* queue)
507 _directAllocate(new_capacity, queue);
512 void _copyFromMemory(
const T* source)
514 m_md->_copyFromMemory(m_ptr, source,
sizeof(T),
_nullRunQueue());
527 void _directFirstAllocateWithAllocator(
Int64 new_capacity, MemoryAllocationOptions options,
528 void* pre_allocated_buffer =
nullptr)
530 IMemoryAllocator* wanted_allocator = options.allocator();
531 if (!wanted_allocator) {
532 wanted_allocator = ArrayMetaData::_defaultAllocator();
533 options.setAllocator(wanted_allocator);
536 m_md->allocation_options = options;
537 if (new_capacity > 0) {
538 if (!pre_allocated_buffer)
539 _allocateMP(new_capacity,
nullptr);
541 _setMPCast(pre_allocated_buffer);
548 void _directAllocate(
Int64 new_capacity, RunQueue* queue)
550 if (!m_md->is_not_null)
552 _allocateMP(new_capacity, queue);
555 void _allocateMP(
Int64 new_capacity, RunQueue* queue)
557 _setMPCast(m_md->_allocate(new_capacity, typeSize(), queue));
560 void _directReAllocate(
Int64 new_capacity, RunQueue* queue)
562 _setMPCast(m_md->_reallocate(_currentMemoryInfo(), new_capacity, typeSize(), queue));
567 void changeAllocator(
const MemoryAllocationOptions& options, RunQueue* queue)
569 _setMPCast(m_md->_changeAllocator(options, _currentMemoryInfo(), typeSize(), queue));
573 void changeAllocator(
const MemoryAllocationOptions& options)
575 _setMPCast(m_md->_changeAllocator(options, _currentMemoryInfo(), typeSize(),
_nullRunQueue()));
593 Int64 s = m_md->size;
594 if ((s + n) > m_md->capacity)
596 for (
Int64 i = 0; i < n; ++i)
597 new (m_ptr + s + i) T(val);
605 const T* ptr = val.
data();
606 Int64 s = m_md->size;
607 if ((s + n) > m_md->capacity)
609 _createRange(s, s + n, ptr);
616 if (m_md->nb_ref == 0) {
623 _destroyRange(0, m_md->
size, IsPODType());
625 void _destroyRange(Int64, Int64, TrueType)
629 void _destroyRange(
Int64 abegin,
Int64 aend, FalseType)
633 for (
Int64 i = abegin; i < aend; ++i)
636 void _createRangeDefault(
Int64,
Int64, TrueType)
639 void _createRangeDefault(
Int64 abegin,
Int64 aend, FalseType)
643 for (
Int64 i = abegin; i < aend; ++i)
646 void _createRange(
Int64 abegin,
Int64 aend, ConstReferenceType value, TrueType)
650 for (
Int64 i = abegin; i < aend; ++i)
653 void _createRange(
Int64 abegin,
Int64 aend, ConstReferenceType value, FalseType)
657 for (
Int64 i = abegin; i < aend; ++i)
658 new (m_ptr + i) T(value);
660 void _createRange(
Int64 abegin,
Int64 aend,
const T* values)
664 for (
Int64 i = abegin; i < aend; ++i) {
665 new (m_ptr + i) T(*values);
669 void _fill(ConstReferenceType value)
671 for (
Int64 i = 0, n =
size(); i < n; ++i)
674 void _clone(
const ThatClassType& orig_array)
676 Int64 that_size = orig_array.size();
678 m_md->size = that_size;
679 m_md->dim1_size = orig_array.m_md->dim1_size;
680 m_md->dim2_size = orig_array.m_md->dim2_size;
681 _createRange(0, that_size, orig_array.m_ptr);
683 template <
typename PodType>
684 void _resizeHelper(
Int64 s, PodType pod_type, RunQueue* queue)
688 if (s > m_md->size) {
690 this->_createRangeDefault(m_md->size, s, pod_type);
693 this->_destroyRange(s, m_md->size, pod_type);
694 if (m_meta_data.is_collective_allocator) {
700 void _resize(
Int64 s)
707 _resizeHelper(s,
TrueType{}, queue);
711 this->_destroyRange(0, m_md->
size, IsPODType());
719 if (s > m_md->size) {
721 this->_createRange(m_md->size, s, value, IsPODType());
724 this->_destroyRange(s, m_md->size, IsPODType());
725 if (m_meta_data.is_collective_allocator) {
731 void _copy(
const T* rhs_begin,
TrueType)
733 _copyFromMemory(rhs_begin);
735 void _copy(
const T* rhs_begin, FalseType)
737 for (Int64 i = 0, n = m_md->
size; i < n; ++i)
738 m_ptr[i] = rhs_begin[i];
740 void _copy(
const T* rhs_begin)
742 _copy(rhs_begin, IsPODType());
755 const T* rhs_begin = rhs.
data();
757 const Int64 current_size = m_md->size;
760 if (abegin >= rhs_begin && abegin < (rhs_begin + rhs_size))
761 ArrayMetaData::overlapError(abegin, m_md->size, rhs_begin, rhs_size);
763 if (rhs_size > current_size) {
766 this->_createRange(m_md->size, rhs_size, rhs_begin + current_size);
769 m_md->size = rhs_size;
772 this->_destroyRange(rhs_size, current_size, IsPODType{});
773 m_md->size = rhs_size;
785 void _move(ThatClassType& rhs) ARCCORE_NOEXCEPT
809 void _swap(ThatClassType& rhs) ARCCORE_NOEXCEPT
811 std::swap(m_ptr, rhs.m_ptr);
821 void _shrink(Int64 new_capacity)
826 if (new_capacity > this->
capacity())
828 if (new_capacity < 4)
846 if (asize > max_size)
848 asize =
static_cast<Integer>(max_size);
857 Span<const T> rhs_span(rhs);
858 if (rhs.allocator() == this->allocator()) {
872 void _setMP(TrueImpl* new_mp)
877 void _setMP2(TrueImpl* new_mp, ArrayMetaData* new_md)
883 if (!m_md->is_allocated_by_new)
889 return m_ptr ==
nullptr;
894 void _setToSharedNull()
897 m_meta_data = ArrayMetaData();
900 void _setMPCast(
void* p)
902 _setMP(
reinterpret_cast<TrueImpl*
>(p));