12#ifndef ARCANE_UTILS_STACKARRAY_H
13#define ARCANE_UTILS_STACKARRAY_H
17#include "arcane/utils/Array.h"
18#include "arcane/utils/MemoryAllocator.h"
44 : m_preallocated_buffer(buf)
45 , m_preallocated_size(size)
50 bool hasRealloc()
const final;
51 void* allocate(
size_t new_size)
final;
52 void* reallocate(
void* current_ptr,
size_t new_size)
final;
53 void deallocate(
void* ptr)
final;
54 size_t adjustCapacity(
size_t wanted_capacity,
size_t)
final
56 return wanted_capacity;
58 size_t guarantedAlignment()
final {
return 0; }
62 void* m_preallocated_buffer =
nullptr;
63 size_t m_preallocated_size = 0;
89template <
typename T, Int32 NbElement = 32>
94 static constexpr Int32 SizeOfType =
static_cast<Int32
>(
sizeof(T));
95 static constexpr Int32 nb_element_in_buf = NbElement;
99 using typename BaseClassType::ConstReferenceType;
100 static constexpr Int32 MemorySize = NbElement * SizeOfType;
106 : m_stack_allocator(m_stack_buffer, MemorySize)
112 SmallArray(Int64 req_size, ConstReferenceType value)
115 this->_resize(req_size, value);
119 explicit SmallArray(Int64 asize)
122 this->_resize(asize);
126 explicit SmallArray(Int32 asize)
127 : SmallArray((Int64)asize)
132 explicit SmallArray(
size_t asize)
133 : SmallArray((Int64)asize)
138 SmallArray(
const ConstArrayView<T>& aview)
139 : SmallArray(Span<const T>(aview))
144 SmallArray(
const Span<const T>& aview)
151 SmallArray(
const ArrayView<T>& aview)
152 : SmallArray(Span<const T>(aview))
157 SmallArray(
const Span<T>& aview)
158 : SmallArray(Span<const T>(aview))
162 SmallArray(std::initializer_list<T> alist)
165 this->_initFromInitializerList(alist);
169 SmallArray(
const Array<T>& rhs)
175 void operator=(
const Array<T>& rhs)
177 this->
copy(rhs.constSpan());
181 void operator=(
const ArrayView<T>& rhs)
187 void operator=(
const Span<T>& rhs)
193 void operator=(
const ConstArrayView<T>& rhs)
199 void operator=(
const Span<const T>& rhs)
205 ~SmallArray()
override
211 this->_internalDeallocate();
217 template <Int32 N> SmallArray(SmallArray<T, N>&& rhs) =
delete;
218 template <Int32 N> SmallArray<T, NbElement> operator=(SmallArray<T, N>&& rhs) =
delete;
222 char m_stack_buffer[MemorySize];
223 impl::StackMemoryAllocator m_stack_allocator;
Classe abstraite de base d'un vecteur.
void _initFromAllocator(IMemoryAllocator *a, Int64 acapacity)
Construit un tableau avec un allocateur spécifique a.
void _initFromSpan(const Span< const T > &view)
Initialise le tableau avec la vue view.
void _reset()
Réinitialise le tableau à un tableau vide.
Classe de base des vecteurs 1D de données.
void copy(Span< const T > rhs)
Copie les valeurs de rhs dans l'instance.
Span< const T > constSpan() const
Vue constante sur ce tableau.
Interface d'un allocateur pour la mémoire.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-