Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
AbstractArray.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* AbstractArray.h (C) 2000-2026 */
9/* */
10/* Base class for arrays. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_ABSTRACTARRAY_H
13#define ARCCORE_COMMON_ABSTRACTARRAY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/Span.h"
18
19#include "arccore/common/ArrayTraits.h"
20#include "arccore/common/ArrayMetaData.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
47class ARCCORE_COMMON_EXPORT AbstractArrayBase
48{
49 public:
50
51 AbstractArrayBase()
52 {
53 m_md = &m_meta_data;
54 }
55 virtual ~AbstractArrayBase() = default;
56
57 public:
58
59 IMemoryAllocator* allocator() const
60 {
61 return m_md->allocation_options.allocator();
62 }
63 MemoryAllocationOptions allocationOptions() const
64 {
65 return m_md->allocation_options;
66 }
68 * \brief Sets the array name for debug information.
69 *
70 * This name can be used, for example, for listing displays.
71 */
72 void setDebugName(const String& name);
74 String debugName() const;
75
76 protected:
77
78 ArrayMetaData* m_md = nullptr;
79 ArrayMetaData m_meta_data;
80
81 protected:
82
84 static constexpr RunQueue* _nullRunQueue() { return nullptr; }
85
92 virtual bool _isUseOwnMetaData() const
93 {
94 return true;
95 }
96
97 protected:
98
99 void _swapMetaData(AbstractArrayBase& rhs)
100 {
101 std::swap(m_md, rhs.m_md);
102 std::swap(m_meta_data, rhs.m_meta_data);
103 _checkSetUseOwnMetaData();
104 rhs._checkSetUseOwnMetaData();
105 }
106
107 void _copyMetaData(const AbstractArrayBase& rhs)
108 {
109 // Move the metadata
110 // Note if m_meta_data is used, m_md must be set to point to our own m_meta_data.
111 m_meta_data = rhs.m_meta_data;
112 m_md = rhs.m_md;
113 _checkSetUseOwnMetaData();
114 }
115
116 void _allocateMetaData()
117 {
118#ifdef ARCCORE_CHECK
119 if (m_md->is_not_null)
120 ArrayMetaData::throwNullExpected();
121#endif
122 if (_isUseOwnMetaData()) {
123 m_meta_data = ArrayMetaData();
124 m_md = &m_meta_data;
125 }
126 else {
127 m_md = new ArrayMetaData();
128 m_md->is_allocated_by_new = true;
129 }
130 m_md->is_not_null = true;
131 }
132
133 void _deallocateMetaData(ArrayMetaData* md)
134 {
135 if (md->is_allocated_by_new)
136 delete md;
137 else
138 *md = ArrayMetaData();
139 }
140
141 void _checkValidSharedArray()
142 {
143#ifdef ARCCORE_CHECK
144 if (m_md->is_not_null && !m_md->is_allocated_by_new)
145 ArrayMetaData::throwInvalidMetaDataForSharedArray();
146#endif
147 }
148
149 private:
150
151 void _checkSetUseOwnMetaData()
152 {
153 if (!m_md->is_allocated_by_new)
154 m_md = &m_meta_data;
155 }
156};
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
168template <typename T>
170: public AbstractArrayBase
171{
172 public:
173
174 typedef typename ArrayTraits<T>::ConstReferenceType ConstReferenceType;
175 typedef typename ArrayTraits<T>::IsPODType IsPODType;
176 typedef AbstractArray<T> ThatClassType;
177 using TrueImpl = T;
178
179 public:
180
182 typedef T value_type;
186 typedef const value_type* const_pointer;
194 typedef ConstReferenceType const_reference;
198 typedef ptrdiff_t difference_type;
199
200 typedef std::reverse_iterator<iterator> reverse_iterator;
201 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
202
203 protected:
204
207 {
208 }
209
210 AbstractArray(ThatClassType&& rhs) ARCCORE_NOEXCEPT
211 : m_ptr(rhs.m_ptr)
212 {
213 _copyMetaData(rhs);
214 rhs._reset();
215 }
216
217 ~AbstractArray() override
218 {
219 --m_md->nb_ref;
221 }
222
223 public:
224
225 AbstractArray(const AbstractArray<T>& rhs) = delete;
226 AbstractArray<T>& operator=(const AbstractArray<T>& rhs) = delete;
227
228 protected:
229
230 static constexpr Int64 typeSize() { return static_cast<Int64>(sizeof(T)); }
231 AllocatedMemoryInfo _currentMemoryInfo() const
232 {
233 return AllocatedMemoryInfo(m_ptr, m_md->size * typeSize(), m_md->capacity * typeSize());
234 }
235
236 protected:
237
243 void _initFromSpan(const Span<const T>& view)
244 {
245 Int64 asize = view.size();
246 if (asize != 0) {
247 _internalAllocate(asize, _nullRunQueue());
248 _createRange(0, asize, view.data());
249 m_md->size = asize;
250 }
251 }
252
263 void* pre_allocated_buffer = nullptr)
264 {
265 _directFirstAllocateWithAllocator(acapacity, o, pre_allocated_buffer);
266 }
267
268 public:
269
271 void dispose()
272 {
273 _destroy();
274 MemoryAllocationOptions options(m_md->allocation_options);
275 _internalDeallocate();
276 _setToSharedNull();
277 // If we have a specific allocator, we must allocate a
278 // block to keep this information.
279 if (options.allocator() != m_md->_allocator())
282 }
283
284 public:
285
286 operator ConstArrayView<T>() const
287 {
288 return ConstArrayView<T>(ARCCORE_CAST_SMALL_SIZE(size()), m_ptr);
289 }
290 operator Span<const T>() const
291 {
292 return Span<const T>(m_ptr, m_md->size);
293 }
294 operator SmallSpan<const T>() const
295 {
296 return SmallSpan<const T>(m_ptr, ARCCORE_CAST_SMALL_SIZE(size()));
297 }
298
299 public:
300
302 Integer size() const { return ARCCORE_CAST_SMALL_SIZE(m_md->size); }
304 Integer length() const { return ARCCORE_CAST_SMALL_SIZE(m_md->size); }
306 Integer capacity() const { return ARCCORE_CAST_SMALL_SIZE(m_md->capacity); }
308 Int64 largeSize() const { return m_md->size; }
310 Int64 largeLength() const { return m_md->size; }
312 Int64 largeCapacity() const { return m_md->capacity; }
314 bool empty() const { return m_md->size == 0; }
316 bool contains(ConstReferenceType v) const
317 {
318 const T* ptr = m_ptr;
319 for (Int64 i = 0, n = m_md->size; i < n; ++i) {
320 if (ptr[i] == v)
321 return true;
322 }
323 return false;
324 }
325
326 public:
327
329 ConstReferenceType operator[](Int64 i) const
330 {
331 ARCCORE_CHECK_AT(i, m_md->size);
332 return m_ptr[i];
333 }
334
335 ConstReferenceType operator()(Int64 i) const
336 {
337 ARCCORE_CHECK_AT(i, m_md->size);
338 return m_ptr[i];
339 }
340
341 public:
342
345 {
346 m_md->_setMemoryLocationHint(new_hint, m_ptr, sizeof(T));
347 }
348
356 {
357 m_md->m_host_device_memory_location = location;
358 }
359
362 {
363 return m_md->m_host_device_memory_location;
364 }
365
366 public:
367
368 friend bool operator==(const AbstractArray<T>& rhs, const AbstractArray<T>& lhs)
369 {
370 return operator==(Span<const T>(rhs), Span<const T>(lhs));
371 }
372
373 friend bool operator!=(const AbstractArray<T>& rhs, const AbstractArray<T>& lhs)
374 {
375 return !(rhs == lhs);
376 }
377
378 friend bool operator==(const AbstractArray<T>& rhs, const Span<const T>& lhs)
379 {
380 return operator==(Span<const T>(rhs), lhs);
381 }
382
383 friend bool operator!=(const AbstractArray<T>& rhs, const Span<const T>& lhs)
384 {
385 return !(rhs == lhs);
386 }
387
388 friend bool operator==(const Span<const T>& rhs, const AbstractArray<T>& lhs)
389 {
390 return operator==(rhs, Span<const T>(lhs));
391 }
392
393 friend bool operator!=(const Span<const T>& rhs, const AbstractArray<T>& lhs)
394 {
395 return !(rhs == lhs);
396 }
397
398 friend std::ostream& operator<<(std::ostream& o, const AbstractArray<T>& val)
399 {
400 o << Span<const T>(val);
401 return o;
402 }
403
404 private:
405
406 using AbstractArrayBase::m_meta_data;
407
408 protected:
409
410 // NOTE: These two fields are used for the TTF display of totalview.
411 // If their order is changed, the corresponding part must be updated
412 // in Arcane's totalview displayer.
413 T* m_ptr = nullptr;
414
415 protected:
416
418 void _reserve(Int64 new_capacity)
419 {
420 if (new_capacity <= m_md->capacity) {
421 // In the case of a collective allocator, we still have to perform a
422 // realloc (the allocator must handle the optimization).
423 if (m_meta_data.is_collective_allocator) {
424 _internalRealloc(m_md->capacity, false);
425 }
426 return;
427 }
428 _internalRealloc(new_capacity, false);
429 }
430
435 void _internalRealloc(Int64 new_capacity, bool compute_capacity, RunQueue* queue = nullptr)
436 {
437 // Note: For shared memory, if one of the pointers is nullptr, then
438 // it is for all processes.
439 if (_isSharedNull()) {
440 if (new_capacity != 0 || m_meta_data.is_collective_allocator)
441 _internalAllocate(new_capacity, queue);
442 return;
443 }
444
445 Int64 acapacity = new_capacity;
446 if (compute_capacity) {
447 acapacity = m_md->capacity;
448 //std::cout << " REALLOC: want=" << wanted_size << " current_capacity=" << capacity << '\n';
449 while (new_capacity > acapacity)
450 acapacity = (acapacity == 0) ? 4 : (acapacity + 1 + acapacity / 2);
451 //std::cout << " REALLOC: want=" << wanted_size << " new_capacity=" << capacity << '\n';
452 }
453 // If the new capacity is less than the current one, do nothing
454 // (except for a collective allocator).
455 if (acapacity <= m_md->capacity) {
456 if (m_meta_data.is_collective_allocator) {
457 _internalReallocate(m_md->capacity, queue);
458 }
459 return;
460 }
461 _internalReallocate(acapacity, queue);
462 }
463
464 void _internalReallocate(Int64 new_capacity, RunQueue* queue)
465 {
466 if constexpr (std::is_trivially_copyable_v<T>) {
467 T* old_ptr = m_ptr;
468 Int64 old_capacity = m_md->capacity;
469 _directReAllocate(new_capacity, queue);
470 bool update = (new_capacity < old_capacity) || (m_ptr != old_ptr);
471 if (update) {
473 }
474 }
475 else {
476 T* old_ptr = m_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]);
484 old_ptr[i].~T();
485 }
486 m_md->nb_ref = old_md->nb_ref;
487 m_md->_deallocate(old_mem_info, queue);
489 }
490 }
491 }
492
493 // Frees the memory
494 void _internalDeallocate(RunQueue* queue = nullptr)
495 {
496 // Note: For shared memory, if one of the pointers is nullptr, then
497 // it is for all processes.
498 if (!_isSharedNull())
499 m_md->_deallocate(_currentMemoryInfo(), queue);
500 if (m_md->is_not_null)
501 _deallocateMetaData(m_md);
502 }
503 void _internalAllocate(Int64 new_capacity, RunQueue* queue)
504 {
505 _directAllocate(new_capacity, queue);
506 m_md->nb_ref = _getNbRef();
508 }
509
510 void _copyFromMemory(const T* source)
511 {
512 m_md->_copyFromMemory(m_ptr, source, sizeof(T), _nullRunQueue());
513 }
514
515 private:
516
526 void* pre_allocated_buffer = nullptr)
527 {
528 IMemoryAllocator* wanted_allocator = options.allocator();
529 if (!wanted_allocator) {
530 wanted_allocator = ArrayMetaData::_defaultAllocator();
531 options.setAllocator(wanted_allocator);
532 }
533 _allocateMetaData();
534 m_md->allocation_options = options;
535 if (new_capacity > 0) {
536 if (!pre_allocated_buffer)
537 _allocateMP(new_capacity, nullptr);
538 else
539 _setMPCast(pre_allocated_buffer);
540 }
541 m_md->nb_ref = _getNbRef();
542 m_md->size = 0;
544 }
545
546 void _directAllocate(Int64 new_capacity, RunQueue* queue)
547 {
548 if (!m_md->is_not_null)
549 _allocateMetaData();
550 _allocateMP(new_capacity, queue);
551 }
552
553 void _allocateMP(Int64 new_capacity, RunQueue* queue)
554 {
555 _setMPCast(m_md->_allocate(new_capacity, typeSize(), queue));
556 }
557
558 void _directReAllocate(Int64 new_capacity, RunQueue* queue)
559 {
560 _setMPCast(m_md->_reallocate(_currentMemoryInfo(), new_capacity, typeSize(), queue));
561 }
562
563 public:
564
565 void changeAllocator(const MemoryAllocationOptions& options, RunQueue* queue)
566 {
567 _setMPCast(m_md->_changeAllocator(options, _currentMemoryInfo(), typeSize(), queue));
569 }
570
571 void changeAllocator(const MemoryAllocationOptions& options)
572 {
573 _setMPCast(m_md->_changeAllocator(options, _currentMemoryInfo(), typeSize(), _nullRunQueue()));
575 }
576
577 public:
578
579 void printInfos(std::ostream& o)
580 {
581 o << " Infos: size=" << m_md->size << " capacity=" << m_md->capacity << '\n';
582 }
583
584 protected:
585
587 virtual void _updateReferences()
588 {
589 }
590
592 {
593 return 1;
594 }
595
596 void _addRange(ConstReferenceType val, Int64 n)
597 {
598 Int64 s = m_md->size;
599 if ((s + n) > m_md->capacity)
600 _internalRealloc(s + n, true);
601 for (Int64 i = 0; i < n; ++i)
602 new (m_ptr + s + i) T(val);
603 m_md->size += n;
604 }
605
608 {
609 Int64 n = val.size();
610 const T* ptr = val.data();
611 Int64 s = m_md->size;
612 if ((s + n) > m_md->capacity)
613 _internalRealloc(s + n, true);
614 _createRange(s, s + n, ptr);
615 m_md->size += n;
616 }
617
620 {
621 if (m_md->nb_ref == 0) {
622 _destroy();
623 _internalDeallocate(_nullRunQueue());
624 }
625 }
626 void _destroy()
627 {
628 _destroyRange(0, m_md->size, IsPODType());
629 }
630 void _destroyRange(Int64, Int64, TrueType)
631 {
632 // Nothing to do for a POD type.
633 }
634 void _destroyRange(Int64 abegin, Int64 aend, FalseType)
635 {
636 if (abegin < 0)
637 abegin = 0;
638 for (Int64 i = abegin; i < aend; ++i)
639 m_ptr[i].~T();
640 }
641 void _createRangeDefault(Int64, Int64, TrueType)
642 {
643 }
644 void _createRangeDefault(Int64 abegin, Int64 aend, FalseType)
645 {
646 if (abegin < 0)
647 abegin = 0;
648 for (Int64 i = abegin; i < aend; ++i)
649 new (m_ptr + i) T();
650 }
651 void _createRange(Int64 abegin, Int64 aend, ConstReferenceType value, TrueType)
652 {
653 if (abegin < 0)
654 abegin = 0;
655 for (Int64 i = abegin; i < aend; ++i)
656 m_ptr[i] = value;
657 }
658 void _createRange(Int64 abegin, Int64 aend, ConstReferenceType value, FalseType)
659 {
660 if (abegin < 0)
661 abegin = 0;
662 for (Int64 i = abegin; i < aend; ++i)
663 new (m_ptr + i) T(value);
664 }
665 void _createRange(Int64 abegin, Int64 aend, const T* values)
666 {
667 if (abegin < 0)
668 abegin = 0;
669 for (Int64 i = abegin; i < aend; ++i) {
670 new (m_ptr + i) T(*values);
671 ++values;
672 }
673 }
674 void _fill(ConstReferenceType value)
675 {
676 for (Int64 i = 0, n = size(); i < n; ++i)
677 m_ptr[i] = value;
678 }
679 void _clone(const ThatClassType& orig_array)
680 {
681 Int64 that_size = orig_array.size();
682 _internalAllocate(that_size, _nullRunQueue());
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);
687 }
688 template <typename PodType>
689 void _resizeHelper(Int64 s, PodType pod_type, RunQueue* queue)
690 {
691 if (s < 0)
692 s = 0;
693 if (s > m_md->size) {
694 this->_internalRealloc(s, false, queue);
695 this->_createRangeDefault(m_md->size, s, pod_type);
696 }
697 else {
698 this->_destroyRange(s, m_md->size, pod_type);
699 if (m_meta_data.is_collective_allocator) {
700 this->_internalRealloc(s, false, queue);
701 }
702 }
703 m_md->size = s;
704 }
705 void _resize(Int64 s)
706 {
707 _resizeHelper(s, IsPODType(), _nullRunQueue());
708 }
710 void _resizeNoInit(Int64 s, RunQueue* queue = nullptr)
711 {
712 _resizeHelper(s, TrueType{}, queue);
713 }
714 void _clear()
715 {
716 this->_destroyRange(0, m_md->size, IsPODType());
717 m_md->size = 0;
718 }
720 void _resize(Int64 s, ConstReferenceType value)
721 {
722 if (s < 0)
723 s = 0;
724 if (s > m_md->size) {
725 this->_internalRealloc(s, false);
726 this->_createRange(m_md->size, s, value, IsPODType());
727 }
728 else {
729 this->_destroyRange(s, m_md->size, IsPODType());
730 if (m_meta_data.is_collective_allocator) {
731 this->_internalRealloc(s, false);
732 }
733 }
734 m_md->size = s;
735 }
736 void _copy(const T* rhs_begin, TrueType)
737 {
738 _copyFromMemory(rhs_begin);
739 }
740 void _copy(const T* rhs_begin, FalseType)
741 {
742 for (Int64 i = 0, n = m_md->size; i < n; ++i)
743 m_ptr[i] = rhs_begin[i];
744 }
745 void _copy(const T* rhs_begin)
746 {
747 _copy(rhs_begin, IsPODType());
748 }
749
759 {
760 const T* rhs_begin = rhs.data();
761 Int64 rhs_size = rhs.size();
762 const Int64 current_size = m_md->size;
763 T* abegin = m_ptr;
764 // Vérifie que \a rhs n'est pas un élément à l'intérieur de ce tableau
765 if (abegin >= rhs_begin && abegin < (rhs_begin + rhs_size))
766 ArrayMetaData::overlapError(abegin, m_md->size, rhs_begin, rhs_size);
767
768 if (rhs_size > current_size) {
769 this->_internalRealloc(rhs_size, false);
770 // Crée les nouveaux éléments
771 this->_createRange(m_md->size, rhs_size, rhs_begin + current_size);
772 // Copie les éléments déjà existant
773 _copy(rhs_begin);
774 m_md->size = rhs_size;
775 }
776 else {
777 this->_destroyRange(rhs_size, current_size, IsPODType{});
778 m_md->size = rhs_size;
779 _copy(rhs_begin);
780 }
781 }
782
790 void _move(ThatClassType& rhs) ARCCORE_NOEXCEPT
791 {
792 if (&rhs == this)
793 return;
794
795 // Comme il n'y a qu'une seule référence sur le tableau actuel, on peut
796 // directement libérer la mémoire.
797 _destroy();
798 _internalDeallocate(_nullRunQueue());
799
800 _setMP(rhs.m_ptr);
801
802 _copyMetaData(rhs);
803
804 // Indique que \a rhs est vide.
805 rhs._reset();
806 }
807
814 void _swap(ThatClassType& rhs) ARCCORE_NOEXCEPT
815 {
816 std::swap(m_ptr, rhs.m_ptr);
817 _swapMetaData(rhs);
818 }
819
820 void _shrink()
821 {
822 _shrink(size());
823 }
824
825 // Reallocates the memory to have a capacity close to \a new_capacity
826 void _shrink(Int64 new_capacity)
827 {
828 if (_isSharedNull())
829 return;
830 // On n'augmente pas la capacité avec cette méthode
831 if (new_capacity > this->capacity())
832 return;
833 if (new_capacity < 4)
834 new_capacity = 4;
835 _internalReallocate(new_capacity, _nullRunQueue());
836 }
837
843 void _reset()
844 {
845 _setToSharedNull();
846 }
847
848 constexpr Integer _clampSizeOffet(Int64 offset, Int32 asize) const
849 {
850 Int64 max_size = m_md->size - offset;
851 if (asize > max_size)
852 // On est certain de ne pas dépasser 32 bits car on est inférieur à asize.
853 asize = static_cast<Integer>(max_size);
854 return asize;
855 }
856
857 // Uniquement pour UniqueArray et UniqueArray2
858 void _assignFromArray(const AbstractArray<T>& rhs)
859 {
860 if (&rhs == this)
861 return;
862 Span<const T> rhs_span(rhs);
863 if (rhs.allocator() == this->allocator()) {
864 _resizeAndCopyView(rhs_span);
865 }
866 else {
867 _destroy();
868 _internalDeallocate(_nullRunQueue());
869 _reset();
870 _initFromAllocator(rhs.allocationOptions(), 0);
871 _initFromSpan(rhs_span);
872 }
873 }
874
875 protected:
876
877 void _setMP(TrueImpl* new_mp)
878 {
879 m_ptr = new_mp;
880 }
881
882 void _setMP2(TrueImpl* new_mp, ArrayMetaData* new_md)
883 {
884 _setMP(new_mp);
885 // Il ne faut garder le nouveau m_md que s'il est alloué
886 // sinon on risque d'avoir des références sur des objets temporaires
887 m_md = new_md;
888 if (!m_md->is_allocated_by_new)
889 m_md = &m_meta_data;
890 }
891
892 bool _isSharedNull()
893 {
894 return m_ptr == nullptr;
895 }
896
897 private:
898
899 void _setToSharedNull()
900 {
901 m_ptr = nullptr;
902 m_meta_data = ArrayMetaData();
903 m_md = &m_meta_data;
904 }
905 void _setMPCast(void* p)
906 {
907 _setMP(reinterpret_cast<TrueImpl*>(p));
908 }
909};
910
911/*---------------------------------------------------------------------------*/
912/*---------------------------------------------------------------------------*/
913
914} // namespace Arcane
915
916/*---------------------------------------------------------------------------*/
917/*---------------------------------------------------------------------------*/
918
919#endif
Types and functions associated with the classes SpanImpl, SmallSpan and Span.
Internal base class for arrays.
static constexpr RunQueue * _nullRunQueue()
Explicit method for a null RunQueue.
virtual bool _isUseOwnMetaData() const
Indicates if m_md refers to m_meta_data.
Abstract base class for a vector.
void _addRange(ConstReferenceType val, Int64 n)
Adds n elements of value val to the end of the array.
Integer capacity() const
Capacity (number of allocated elements) of the vector.
void _addRange(Span< const T > val)
Adds n elements of value val to the end of the array.
void _internalSetHostDeviceMemoryLocation(eHostDeviceMemoryLocation location)
Sets the physical location of the memory region.
virtual void _updateReferences()
Update references.
void _checkFreeMemory()
Destroys the instance if no one references it.
ConstReferenceType operator[](Int64 i) const
Element at index i.
void dispose()
Frees the memory used by the array.
AbstractArray()
Constructs an empty vector with the default allocator.
Integer size() const
Number of elements in the vector.
void _initFromSpan(const Span< const T > &view)
Initializes the array with the view view.
void _move(ThatClassType &rhs) ARCCORE_NOEXCEPT
Implements the move assignment operator.
void _initFromAllocator(MemoryAllocationOptions o, Int64 acapacity, void *pre_allocated_buffer=nullptr)
Constructs an empty vector with a specific allocator a.
ArrayIterator< pointer > iterator
void _resize(Int64 s, ConstReferenceType value)
Redimensionne et remplit les nouvelles valeurs avec value.
void setMemoryLocationHint(eMemoryLocationHint new_hint)
Modifies the memory location information.
bool empty() const
Capacity (number of allocated elements) of the vector.
eHostDeviceMemoryLocation hostDeviceMemoryLocation() const
Sets the physical location of the memory region.
Int64 largeSize() const
Number of elements in the vector (in 64 bits).
bool contains(ConstReferenceType v) const
True if the array contains the value element v.
Int64 largeCapacity() const
Capacity (number of allocated elements) of the vector (in 64 bits).
Int64 largeLength() const
Number of elements in the vector (in 64 bits).
void _directFirstAllocateWithAllocator(Int64 new_capacity, MemoryAllocationOptions options, void *pre_allocated_buffer=nullptr)
Performs the first allocation.
void _internalRealloc(Int64 new_capacity, bool compute_capacity, RunQueue *queue=nullptr)
Reallocates the array for a new capacity equal to new_capacity.
void _reserve(Int64 new_capacity)
Reserves memory for new_capacity elements.
void _resizeAndCopyView(Span< const T > rhs)
Redimensionne l'instance et recopie les valeurs de rhs.
virtual Integer _getNbRef()
Update references.
ArrayIterator< const_pointer > const_iterator
void _resizeNoInit(Int64 s, RunQueue *queue=nullptr)
Redimensionne sans initialiser les nouvelles valeurs.
AbstractArray(ThatClassType &&rhs) ARCCORE_NOEXCEPT
Move constructor. Should only be used by UniqueArray.
void _swap(ThatClassType &rhs) ARCCORE_NOEXCEPT
Swaps the values of the instance with those of rhs.
ConstReferenceType operator()(Int64 i) const
Element at index i.
void _reset()
Resets the array to an empty array.
Integer length() const
Number of elements in the vector.
String debugName() const
void setDebugName(const String &name)
Iterator over Arccore array classes.
Array Metadata.
bool is_not_null
Indicates if this instance is not the null instance (shared by all SharedArray).
Int64 size
Number of elements in the array (for 1D arrays).
Int64 capacity
Number of allocated elements.
Int32 nb_ref
Number of references on the instance.
bool is_allocated_by_new
Indicates if this instance was allocated by the new operator.
Constant view of an array of type T.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
Definition Span.h:539
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:327
View of an array of elements of type T.
Definition Span.h:635
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
eMemoryLocationHint
Indices for expected memory location.
eHostDeviceMemoryLocation
Physical location of a memory address.
std::int32_t Int32
Signed integer type of 32 bits.
Structure equivalent to the boolean value true.