Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Arcane::DefaultMemoryAllocator Class Reference

Memory allocator via malloc/realloc/free. More...

#include </__w/arcaneframework.github.io/arcaneframework.github.io/framework/arccore/src/common/arccore/common/DefaultMemoryAllocator.h>

Inheritance diagram for Arcane::DefaultMemoryAllocator:
Collaboration diagram for Arcane::DefaultMemoryAllocator:

Public Member Functions

bool hasRealloc (MemoryAllocationArgs) const override
 Indicates whether the allocator supports realloc semantics.
AllocatedMemoryInfo allocate (MemoryAllocationArgs, Int64 new_size) override
 Allocates memory for new_size bytes and returns the pointer.
AllocatedMemoryInfo reallocate (MemoryAllocationArgs, AllocatedMemoryInfo current_ptr, Int64 new_size) override
 Reallocates memory for new_size bytes and returns the pointer.
void deallocate (MemoryAllocationArgs, AllocatedMemoryInfo ptr) override
 Frees the memory whose base address is ptr.
Int64 adjustedCapacity (MemoryAllocationArgs, Int64 wanted_capacity, Int64 element_size) const override
 Adjusts the capacity based on the element size.
size_t guaranteedAlignment (MemoryAllocationArgs) const override
 Value of the alignment guaranteed by the allocator.
eMemoryResource memoryResource () const override
 Memory resource provided by the allocator.
Public Member Functions inherited from Arcane::IMemoryAllocator
virtual ~IMemoryAllocator ()=default
 Destroys 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 bool isCollective () const
 Indicates whether calls to the allocator must be performed collectively.

Static Private Attributes

static DefaultMemoryAllocator shared_null_instance

Friends

class ArrayMetaData

Detailed Description

Memory allocator via malloc/realloc/free.

TODO: mark methods as 'final'.

Definition at line 33 of file DefaultMemoryAllocator.h.

Member Function Documentation

◆ adjustedCapacity()

Int64 Arcane::DefaultMemoryAllocator::adjustedCapacity ( MemoryAllocationArgs args,
Int64 wanted_capacity,
Int64 element_size ) const
overridevirtual

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.

Implements Arcane::IMemoryAllocator.

Definition at line 117 of file MemoryAllocator.cc.

◆ allocate()

AllocatedMemoryInfo Arcane::DefaultMemoryAllocator::allocate ( MemoryAllocationArgs args,
Int64 new_size )
overridevirtual

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.

Implements Arcane::IMemoryAllocator.

Reimplemented in Arcane::PrintableMemoryAllocator, and Arccore::PrintableMemoryAllocator.

Definition at line 90 of file MemoryAllocator.cc.

Referenced by Arcane::PrintableMemoryAllocator::allocate().

Here is the caller graph for this function:

◆ deallocate()

void Arcane::DefaultMemoryAllocator::deallocate ( MemoryAllocationArgs args,
AllocatedMemoryInfo ptr )
overridevirtual

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.

Implements Arcane::IMemoryAllocator.

Reimplemented in Arcane::PrintableMemoryAllocator, and Arccore::PrintableMemoryAllocator.

Definition at line 108 of file MemoryAllocator.cc.

References Arcane::AllocatedMemoryInfo::baseAddress().

Referenced by Arcane::PrintableMemoryAllocator::deallocate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ guaranteedAlignment()

size_t Arcane::DefaultMemoryAllocator::guaranteedAlignment ( MemoryAllocationArgs args) const
inlineoverridevirtual

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.

Implements Arcane::IMemoryAllocator.

Definition at line 49 of file DefaultMemoryAllocator.h.

◆ hasRealloc()

bool Arcane::DefaultMemoryAllocator::hasRealloc ( MemoryAllocationArgs ) const
overridevirtual

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 from Arcane::IMemoryAllocator.

Definition at line 81 of file MemoryAllocator.cc.

◆ memoryResource()

eMemoryResource Arcane::DefaultMemoryAllocator::memoryResource ( ) const
inlineoverridevirtual

Memory resource provided by the allocator.

Reimplemented from Arcane::IMemoryAllocator.

Definition at line 50 of file DefaultMemoryAllocator.h.

References Arcane::Host.

◆ reallocate()

AllocatedMemoryInfo Arcane::DefaultMemoryAllocator::reallocate ( MemoryAllocationArgs args,
AllocatedMemoryInfo current_ptr,
Int64 new_size )
overridevirtual

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.

Implements Arcane::IMemoryAllocator.

Reimplemented in Arcane::PrintableMemoryAllocator, and Arccore::PrintableMemoryAllocator.

Definition at line 99 of file MemoryAllocator.cc.

References Arcane::AllocatedMemoryInfo::baseAddress().

Referenced by Arcane::PrintableMemoryAllocator::reallocate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ArrayMetaData

friend class ArrayMetaData
friend

Definition at line 36 of file DefaultMemoryAllocator.h.

Member Data Documentation

◆ shared_null_instance

DefaultMemoryAllocator Arcane::DefaultMemoryAllocator::shared_null_instance
staticprivate

Definition at line 40 of file DefaultMemoryAllocator.h.


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