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/common/DefaultMemoryAllocator.h"
20#include "arccore/common/AlignedMemoryAllocator.h"
21#include "arccore/common/AllocatedMemoryInfo.h"
27#if defined(ARCCORE_OS_WIN32)
33#if defined(ARCCORE_OS_LINUX) || defined(ARCCORE_OS_MACOS)
34#define ARCCORE_USE_POSIX_MEMALIGN
93 return { ::malloc(new_size), new_size };
102 return { ::realloc(current_ptr.
baseAddress(), new_size), new_size };
120 return wanted_capacity;
150#if defined(ARCCORE_USE_POSIX_MEMALIGN)
152 int e = ::posix_memalign(&ptr, m_alignment, new_size);
158#elif defined(ARCCORE_OS_WIN32)
171#if defined(ARCCORE_USE_POSIX_MEMALIGN)
172 ARCCORE_UNUSED(current_ptr);
173 ARCCORE_UNUSED(new_size);
175#elif defined(ARCCORE_OS_WIN32)
188#if defined(ARCCORE_USE_POSIX_MEMALIGN)
190#elif defined(ARCCORE_OS_WIN32)
202 bool is_verbose =
false;
206adjustMemoryCapacity(
size_t wanted_capacity,
size_t element_size,
size_t alignment)
208 if (element_size == 0)
209 return wanted_capacity;
214 size_t block_size = alignment / element_size;
216 return wanted_capacity;
221 size_t nb_element = alignment % element_size;
223 return wanted_capacity;
226 std::cout <<
" wanted_capacity=" << wanted_capacity
227 <<
" element_size=" << element_size
228 <<
" block_size=" << block_size <<
'\n';
231 size_t modulo = wanted_capacity % block_size;
233 wanted_capacity += (block_size - modulo);
235 std::cout <<
" final_wanted_capacity=" << wanted_capacity
236 <<
" modulo=" << modulo <<
'\n';
237 ARCCORE_ASSERT(((wanted_capacity % block_size) == 0), (
"Bad capacity"));
238 return wanted_capacity;
247 return adjustMemoryCapacity(wanted_capacity, element_size, m_alignment);
260 std::cout <<
"DEF_ARRAY_ALLOCATE new_size=" << new_size <<
" ptr=" << mem_info.
baseAddress() <<
'\n';
271 std::cout <<
"DEF_ARRAY_REALLOCATE new_size=" << new_size
283 std::cout <<
"DEF_ARRAY_DEALLOCATE ptr=" << ptr.
baseAddress() <<
'\n';
Memory allocator with specific memory alignment.
AllocatedMemoryInfo allocate(MemoryAllocationArgs args, Int64 new_size) override
static constexpr Integer simdAlignment()
Alignment for structures using vectorization.
void deallocate(MemoryAllocationArgs args, AllocatedMemoryInfo ptr) override
Frees the memory whose base address is ptr.
Int64 adjustedCapacity(MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const override
Adjusts the capacity based on the element size.
AllocatedMemoryInfo reallocate(MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size) override
Reallocates memory for new_size bytes and returns the pointer.
static constexpr Integer cacheLineAlignment()
Alignment for a cache line.
Information about an allocated memory region.
void * baseAddress() const
Address of the start of the allocated region.
Int64 size() const
Size in bytes of the used memory region. (-1) if unknown.
Exception when an argument is invalid.
Memory allocator via malloc/realloc/free.
void deallocate(MemoryAllocationArgs, AllocatedMemoryInfo ptr) override
Frees the memory whose base address is ptr.
AllocatedMemoryInfo reallocate(MemoryAllocationArgs, AllocatedMemoryInfo current_ptr, Int64 new_size) override
Reallocates memory for new_size bytes and returns the pointer.
Int64 adjustedCapacity(MemoryAllocationArgs, Int64 wanted_capacity, Int64 element_size) const override
Adjusts the capacity based on the element size.
AllocatedMemoryInfo allocate(MemoryAllocationArgs, Int64 new_size) override
Allocates memory for new_size bytes and returns the pointer.
bool hasRealloc(MemoryAllocationArgs) const override
Indicates whether the allocator supports realloc semantics.
virtual void copyMemory(MemoryAllocationArgs args, AllocatedMemoryInfo destination, AllocatedMemoryInfo source)
Copies memory between two regions.
virtual void notifyMemoryArgsChanged(MemoryAllocationArgs old_args, MemoryAllocationArgs new_args, AllocatedMemoryInfo ptr)
Notifies of a change in instance-specific arguments.
virtual size_t guarantedAlignment(MemoryAllocationArgs args) const
Value of the alignment guaranteed by the allocator.
virtual size_t guaranteedAlignment(MemoryAllocationArgs args) const =0
Value of the alignment guaranteed by the allocator.
Class containing information to specialize allocations.
AllocatedMemoryInfo reallocate(MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size) override
Reallocates memory for new_size bytes and returns the pointer.
void deallocate(MemoryAllocationArgs args, AllocatedMemoryInfo ptr) override
Frees the memory whose base address is ptr.
AllocatedMemoryInfo allocate(MemoryAllocationArgs args, Int64 new_size) override
Allocates memory for new_size bytes and returns the pointer.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.