14#include "arcane/utils/SmallArray.h"
28const bool is_verbose =
false;
34bool StackMemoryAllocator::
43void* StackMemoryAllocator::
44allocate(
size_t new_size)
46 if (new_size <= m_preallocated_size) {
48 std::cout <<
"ALLOCATE: use preallocated s=" << new_size <<
"\n";
49 return m_preallocated_buffer;
53 std::cout <<
"ALLOCATE: use malloc s=" << new_size <<
"\n";
54 return std::malloc(new_size);
60void* StackMemoryAllocator::
61reallocate(
void* current_ptr,
size_t new_size)
63 if (current_ptr != m_preallocated_buffer) {
64 if (new_size < m_preallocated_size) {
71 std::cout <<
"REALLOCATE: use own buffer from realloc s=" << new_size <<
"\n";
72 std::memcpy(m_preallocated_buffer, current_ptr, new_size);
73 std::free(current_ptr);
74 return m_preallocated_buffer;
77 std::cout <<
"REALLOCATE: use realloc s=" << new_size <<
"\n";
78 return std::realloc(current_ptr, new_size);
81 if (new_size <= m_preallocated_size) {
83 std::cout <<
"REALLOCATE: use buffer because small size s=" << new_size <<
"\n";
84 return m_preallocated_buffer;
89 std::cout <<
"REALLOCATE: use malloc and copy s=" << new_size <<
"\n";
90 void* new_ptr = std::malloc(new_size);
91 std::memcpy(new_ptr, m_preallocated_buffer, m_preallocated_size);
98void StackMemoryAllocator::
101 if (ptr != m_preallocated_buffer)