14#include "arccore/base/ArgumentException.h"
15#include "arccore/base/NotSupportedException.h"
16#include "arccore/base/NotImplementedException.h"
17#include "arccore/base/TraceInfo.h"
19#include "arccore/collections/IMemoryAllocator.h"
25#if defined(ARCCORE_OS_WIN32)
31#if defined(ARCCORE_OS_LINUX) || defined(ARCCORE_OS_MACOS)
32#define ARCCORE_USE_POSIX_MEMALIGN
44DefaultMemoryAllocator DefaultMemoryAllocator::shared_null_instance;
70 std::memcpy(destination.
baseAddress(), source.baseAddress(), source.size());
91 return { ::malloc(new_size), new_size };
100 return { ::realloc(current_ptr.
baseAddress(), new_size), new_size };
118 return wanted_capacity;
147#if defined(ARCCORE_USE_POSIX_MEMALIGN)
149 int e = ::posix_memalign(&ptr, m_alignment, new_size);
155#elif defined(ARCCORE_OS_WIN32)
168#if defined(ARCCORE_USE_POSIX_MEMALIGN)
169 ARCCORE_UNUSED(current_ptr);
170 ARCCORE_UNUSED(new_size);
172#elif defined(ARCCORE_OS_WIN32)
185#if defined(ARCCORE_USE_POSIX_MEMALIGN)
187#elif defined(ARCCORE_OS_WIN32)
199 bool is_verbose =
false;
203adjustMemoryCapacity(
size_t wanted_capacity,
size_t element_size,
size_t alignment)
205 if (element_size == 0)
206 return wanted_capacity;
211 size_t block_size = alignment / element_size;
213 return wanted_capacity;
218 size_t nb_element = alignment % element_size;
220 return wanted_capacity;
223 std::cout <<
" wanted_capacity=" << wanted_capacity
224 <<
" element_size=" << element_size
225 <<
" block_size=" << block_size <<
'\n';
228 size_t modulo = wanted_capacity % block_size;
230 wanted_capacity += (block_size - modulo);
232 std::cout <<
" final_wanted_capacity=" << wanted_capacity
233 <<
" modulo=" << modulo <<
'\n';
234 ARCCORE_ASSERT(((wanted_capacity % block_size) == 0), (
"Bad capacity"));
235 return wanted_capacity;
244 return adjustMemoryCapacity(wanted_capacity, element_size, m_alignment);
257 std::cout <<
"DEF_ARRAY_ALLOCATE new_size=" << new_size <<
" ptr=" << mem_info.
baseAddress() <<
'\n';
268 std::cout <<
"DEF_ARRAY_REALLOCATE new_size=" << new_size
280 std::cout <<
"DEF_ARRAY_DEALLOCATE ptr=" << ptr.
baseAddress() <<
'\n';
Allocateur mémoire avec alignement mémoire spécifique.
AllocatedMemoryInfo reallocate(MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size) override
Réalloue de la mémoire pour new_size octets et retourne le pointeur.
static constexpr Integer simdAlignment()
Alignement pour les structures utilisant la vectorisation.
static constexpr Integer cacheLineAlignment()
Alignement pour une ligne de cache.
AllocatedMemoryInfo allocate(MemoryAllocationArgs args, Int64 new_size) override
void deallocate(MemoryAllocationArgs args, AllocatedMemoryInfo ptr) override
Libère la mémoire dont l'adresse de base est ptr.
Int64 adjustedCapacity(MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const override
Ajuste la capacité suivant la taille d'élément.
Informations sur une zone mémoire allouée.
void * baseAddress() const
Adresse du début de la zone allouée.
Exception lorsqu'un argument est invalide.
bool hasRealloc(MemoryAllocationArgs) const override
Indique si l'allocateur supporte la sémantique de realloc.
AllocatedMemoryInfo allocate(MemoryAllocationArgs, Int64 new_size) override
Alloue de la mémoire pour new_size octets et retourne le pointeur.
Int64 adjustedCapacity(MemoryAllocationArgs, Int64 wanted_capacity, Int64 element_size) const override
Ajuste la capacité suivant la taille d'élément.
AllocatedMemoryInfo reallocate(MemoryAllocationArgs, AllocatedMemoryInfo current_ptr, Int64 new_size) override
Réalloue de la mémoire pour new_size octets et retourne le pointeur.
void deallocate(MemoryAllocationArgs, AllocatedMemoryInfo ptr) override
Libère la mémoire dont l'adresse de base est ptr.
virtual void notifyMemoryArgsChanged(MemoryAllocationArgs old_args, MemoryAllocationArgs new_args, AllocatedMemoryInfo ptr)
Notifie du changement des arguments spécifiques à l'instance.
virtual size_t guarantedAlignment(MemoryAllocationArgs args) const
Valeur de l'alignement garanti par l'allocateur.
virtual size_t guaranteedAlignment(MemoryAllocationArgs args) const =0
Valeur de l'alignement garanti par l'allocateur.
virtual void copyMemory(MemoryAllocationArgs args, AllocatedMemoryInfo destination, AllocatedMemoryInfo source)
Copie la mémoire entre deux zones.
Classe contenant des informations pour spécialiser les allocations.
Exception lorsqu'une fonction n'est pas implémentée.
Exception lorsqu'une opération n'est pas supportée.
AllocatedMemoryInfo allocate(MemoryAllocationArgs args, Int64 new_size) override
Alloue de la mémoire pour new_size octets et retourne le pointeur.
AllocatedMemoryInfo reallocate(MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size) override
Réalloue de la mémoire pour new_size octets et retourne le pointeur.
void deallocate(MemoryAllocationArgs args, AllocatedMemoryInfo ptr) override
Libère la mémoire dont l'adresse de base est ptr.
Espace de nom de Arccore.
std::int64_t Int64
Type entier signé sur 64 bits.