14#include "arcane/utils/SmallArray.h"
28 const bool is_verbose =
false;
34AllocatedMemoryInfo StackMemoryAllocator::
35allocate(MemoryAllocationArgs, Int64 new_size)
37 if (new_size <= m_preallocated_size) {
39 std::cout <<
"ALLOCATE: use preallocated s=" << new_size <<
"\n";
40 return { m_preallocated_buffer, new_size };
44 std::cout <<
"ALLOCATE: use malloc s=" << new_size <<
"\n";
45 return { std::malloc(new_size), new_size };
51AllocatedMemoryInfo StackMemoryAllocator::
52reallocate(MemoryAllocationArgs, AllocatedMemoryInfo current_ptr_info, Int64 new_size)
54 void* current_ptr = current_ptr_info.baseAddress();
55 if (current_ptr != m_preallocated_buffer) {
56 if (new_size < m_preallocated_size) {
63 std::cout <<
"REALLOCATE: use own buffer from realloc s=" << new_size <<
"\n";
64 std::memcpy(m_preallocated_buffer, current_ptr, new_size);
65 std::free(current_ptr);
66 return { m_preallocated_buffer, new_size };
69 std::cout <<
"REALLOCATE: use realloc s=" << new_size <<
"\n";
70 return { std::realloc(current_ptr, new_size), new_size };
73 if (new_size <= m_preallocated_size) {
75 std::cout <<
"REALLOCATE: use buffer because small size s=" << new_size <<
"\n";
76 return { m_preallocated_buffer, new_size };
81 std::cout <<
"REALLOCATE: use malloc and copy s=" << new_size <<
"\n";
82 void* new_ptr = std::malloc(new_size);
83 std::memcpy(new_ptr, m_preallocated_buffer, m_preallocated_size);
84 return { new_ptr, new_size };
94 if (ptr != m_preallocated_buffer)
void deallocate(MemoryAllocationArgs args, AllocatedMemoryInfo ptr) final
Libère la mémoire dont l'adresse de base est ptr.
Informations sur une zone mémoire allouée.
void * baseAddress() const
Adresse du début de la zone allouée.
Classe contenant des informations pour spécialiser les allocations.