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)
54 Int64 adjustedCapacity(
MemoryAllocationArgs, Int64 wanted_capacity, Int64)
const final {
return wanted_capacity; }
59 void* m_preallocated_buffer =
nullptr;
60 Int64 m_preallocated_size = 0;
86template <
typename T, Int32 NbElement = 32>
90 using BaseClassType = AbstractArray<T>;
91 static constexpr Int32 SizeOfType =
static_cast<Int32
>(
sizeof(T));
92 static constexpr Int32 nb_element_in_buf = NbElement;
96 using typename BaseClassType::ConstReferenceType;
97 static constexpr Int32 MemorySize = NbElement * SizeOfType;
103 : m_stack_allocator(m_stack_buffer, MemorySize)
109 SmallArray(Int64 req_size, ConstReferenceType value)
112 this->_resize(req_size, value);
116 explicit SmallArray(Int64 asize)
119 this->_resize(asize);
123 explicit SmallArray(Int32 asize)
124 : SmallArray((Int64)asize)
129 explicit SmallArray(
size_t asize)
130 : SmallArray((Int64)asize)
135 SmallArray(
const ConstArrayView<T>& aview)
136 : SmallArray(Span<const T>(aview))
141 SmallArray(
const Span<const T>& aview)
148 SmallArray(
const ArrayView<T>& aview)
149 : SmallArray(Span<const T>(aview))
154 SmallArray(
const Span<T>& aview)
155 : SmallArray(Span<const T>(aview))
159 SmallArray(std::initializer_list<T> alist)
162 this->_initFromInitializerList(alist);
166 SmallArray(
const Array<T>& rhs)
172 void operator=(
const Array<T>& rhs)
174 this->
copy(rhs.constSpan());
178 void operator=(
const ArrayView<T>& rhs)
184 void operator=(
const Span<T>& rhs)
190 void operator=(
const ConstArrayView<T>& rhs)
196 void operator=(
const Span<const T>& rhs)
202 ~SmallArray()
override
208 this->_internalDeallocate();
214 template <Int32 N> SmallArray(SmallArray<T, N>&& rhs) =
delete;
215 template <Int32 N> SmallArray<T, NbElement> operator=(SmallArray<T, N>&& rhs) =
delete;
219 char m_stack_buffer[MemorySize];
220 impl::StackMemoryAllocator m_stack_allocator;
size_t guarantedAlignment(MemoryAllocationArgs) const final
Valeur de l'alignement garanti par l'allocateur.
bool hasRealloc(MemoryAllocationArgs) const final
Indique si l'allocateur supporte la sémantique de realloc.
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.
Informations sur une zone mémoire allouée.
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 de la version 3 de IMemoryAllocator.
Classe contenant des informations pour spécialiser les allocations.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-