Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Arcane::IMemoryAllocator Class Referenceabstract

Interface for a memory allocator. More...

#include <arccore/common/IMemoryAllocator.h>

Public Member Functions

virtual ~IMemoryAllocator ()=default
 Destroys the allocator.
virtual bool hasRealloc (MemoryAllocationArgs) const
 Indicates whether the allocator supports realloc semantics.
virtual AllocatedMemoryInfo allocate (MemoryAllocationArgs args, Int64 new_size)=0
 Allocates memory for new_size bytes and returns the pointer.
virtual AllocatedMemoryInfo reallocate (MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size)=0
 Reallocates memory for new_size bytes and returns the pointer.
virtual void deallocate (MemoryAllocationArgs args, AllocatedMemoryInfo ptr)=0
 Frees the memory whose base address is ptr.
virtual Int64 adjustedCapacity (MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const =0
 Adjusts the capacity based on the element size.
virtual size_t guaranteedAlignment (MemoryAllocationArgs args) const =0
 Value of the alignment guaranteed by the allocator.
virtual size_t guarantedAlignment (MemoryAllocationArgs args) const
 Value of the alignment guaranteed by the allocator.
virtual void notifyMemoryArgsChanged (MemoryAllocationArgs old_args, MemoryAllocationArgs new_args, AllocatedMemoryInfo ptr)
 Notifies of a change in instance-specific arguments.
virtual void copyMemory (MemoryAllocationArgs args, AllocatedMemoryInfo destination, AllocatedMemoryInfo source)
 Copies memory between two regions.
virtual eMemoryResource memoryResource () const
 Memory resource provided by the allocator.
virtual bool isCollective () const
 Indicates whether calls to the allocator must be performed collectively.

Detailed Description

Interface for a memory allocator.

This class defines an interface for the memory allocation used by Arccore array classes (Array, UniqueArray).

An instance of this class must remain valid as long as there are arrays using it. Since the allocator is transferred during copies, it is preferable that allocators be static objects whose lifetime is that of the program.

Allocators do not have specific mutable state and must function in multi-threading.

Definition at line 42 of file arccore/src/common/arccore/common/IMemoryAllocator.h.

Constructor & Destructor Documentation

◆ ~IMemoryAllocator()

virtual Arcane::IMemoryAllocator::~IMemoryAllocator ( )
virtualdefault

Destroys the allocator.

All objects allocated by the allocator must have been deallocated.

Member Function Documentation

◆ adjustedCapacity()

virtual Int64 Arcane::IMemoryAllocator::adjustedCapacity ( MemoryAllocationArgs args,
Int64 wanted_capacity,
Int64 element_size ) const
pure virtual

Adjusts the capacity based on the element size.

This method is used to optionally modify the number of allocated elements based on their size. This allows, for example, aligned allocators to ensure that the number of elements allocated is a multiple of this alignment.

Implemented in Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arccore::AlignedMemoryAllocator, and Arccore::DefaultMemoryAllocator.

◆ allocate()

virtual AllocatedMemoryInfo Arcane::IMemoryAllocator::allocate ( MemoryAllocationArgs args,
Int64 new_size )
pure virtual

Allocates memory for new_size bytes and returns the pointer.

The semantics are equivalent to malloc():

  • new_size can be zero, in which case the returned pointer is either null or a specific value
  • the returned pointer may be null if the memory could not be allocated.

Implemented in Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::PrintableMemoryAllocator, Arccore::AlignedMemoryAllocator, Arccore::DefaultMemoryAllocator, and Arccore::PrintableMemoryAllocator.

◆ copyMemory()

void Arcane::IMemoryAllocator::copyMemory ( MemoryAllocationArgs args,
AllocatedMemoryInfo destination,
AllocatedMemoryInfo source )
virtual

Copies memory between two regions.

The default implementation uses std::memcpy().

Parameters
argsmemory region arguments
destinationdestination of the copy
sourcesource of the copy

Definition at line 68 of file MemoryAllocator.cc.

References Arcane::AllocatedMemoryInfo::baseAddress(), and Arcane::AllocatedMemoryInfo::size().

Referenced by guaranteedAlignment().

◆ deallocate()

virtual void Arcane::IMemoryAllocator::deallocate ( MemoryAllocationArgs args,
AllocatedMemoryInfo ptr )
pure virtual

Frees the memory whose base address is ptr.

The pointer ptr must have been allocated via a call to allocate() or reallocate() on this instance.

The semantics of this method are equivalent to free(), and thus ptr may be null, in which case no operation is performed.

Implemented in Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::PrintableMemoryAllocator, Arccore::AlignedMemoryAllocator, Arccore::DefaultMemoryAllocator, and Arccore::PrintableMemoryAllocator.

◆ guarantedAlignment()

size_t Arcane::IMemoryAllocator::guarantedAlignment ( MemoryAllocationArgs args) const
virtual

Value of the alignment guaranteed by the allocator.

See also
guaranteedAlignment()

Definition at line 51 of file MemoryAllocator.cc.

References guaranteedAlignment().

Referenced by guaranteedAlignment().

◆ guaranteedAlignment()

virtual size_t Arcane::IMemoryAllocator::guaranteedAlignment ( MemoryAllocationArgs args) const
pure virtual

Value of the alignment guaranteed by the allocator.

This method ensures that an allocator has sufficient alignment for certain operations such as vectorization, for example.

If there is no guarantee, it returns 0.

Implemented in Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arccore::AlignedMemoryAllocator, and Arccore::DefaultMemoryAllocator.

References copyMemory(), guarantedAlignment(), and notifyMemoryArgsChanged().

Referenced by guarantedAlignment().

◆ hasRealloc()

virtual bool Arcane::IMemoryAllocator::hasRealloc ( MemoryAllocationArgs ) const
inlinevirtual

Indicates whether the allocator supports realloc semantics.

Default C allocators (malloc/realloc/free) obviously support realloc, but this is not necessarily the case for specific allocators with memory alignment (such as posix_memalign).

Reimplemented in Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arccore::AlignedMemoryAllocator, and Arccore::DefaultMemoryAllocator.

Definition at line 63 of file arccore/src/common/arccore/common/IMemoryAllocator.h.

◆ isCollective()

virtual bool Arcane::IMemoryAllocator::isCollective ( ) const
inlinevirtual

Indicates whether calls to the allocator must be performed collectively.

Definition at line 154 of file arccore/src/common/arccore/common/IMemoryAllocator.h.

◆ memoryResource()

virtual eMemoryResource Arcane::IMemoryAllocator::memoryResource ( ) const
inlinevirtual

◆ notifyMemoryArgsChanged()

void Arcane::IMemoryAllocator::notifyMemoryArgsChanged ( MemoryAllocationArgs old_args,
MemoryAllocationArgs new_args,
AllocatedMemoryInfo ptr )
virtual

Notifies of a change in instance-specific arguments.

Parameters
ptrallocated memory region
old_argsold value of the arguments
new_argsnew value of the arguments

Definition at line 60 of file MemoryAllocator.cc.

Referenced by guaranteedAlignment(), and Arcane::Array2< T >::setDebugName().

◆ reallocate()

virtual AllocatedMemoryInfo Arcane::IMemoryAllocator::reallocate ( MemoryAllocationArgs args,
AllocatedMemoryInfo current_ptr,
Int64 new_size )
pure virtual

Reallocates memory for new_size bytes and returns the pointer.

The pointer current_ptr must have been allocated via a call to allocate() or reallocate() on this instance.

The semantics of this method are equivalent to realloc():

  • current_ptr may be null, in which case this call is equivalent to allocate().
  • the returned pointer may be null if the memory could not be allocated.

Implemented in Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::PrintableMemoryAllocator, Arccore::AlignedMemoryAllocator, Arccore::DefaultMemoryAllocator, and Arccore::PrintableMemoryAllocator.


The documentation for this class was generated from the following files: