Memory allocator with specific memory alignment. More...
#include <arccore/common/AlignedMemoryAllocator.h>
Public Member Functions | |
| bool | hasRealloc (MemoryAllocationArgs) const override |
| Indicates whether the allocator supports realloc semantics. | |
| AllocatedMemoryInfo | allocate (MemoryAllocationArgs args, Int64 new_size) override |
| 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. | |
| Int64 | adjustedCapacity (MemoryAllocationArgs args, 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 Public Member Functions | |
| static constexpr Integer | simdAlignment () |
| Alignment for structures using vectorization. | |
| static constexpr Integer | cacheLineAlignment () |
| Alignment for a cache line. | |
| static AlignedMemoryAllocator * | Simd () |
| Allocator guaranteeing alignment to use vectorization on the target platform. | |
| static AlignedMemoryAllocator * | CacheLine () |
| Allocator guaranteeing alignment to a cache line. | |
Protected Member Functions | |
| AlignedMemoryAllocator (Int32 alignment) | |
Memory allocator with specific memory alignment.
This class is used via the two public methods Simd() and CacheLine(), which return an allocator with adequate alignment to allow vectorization, and an allocator aligned to a cache line, respectively.
Definition at line 44 of file AlignedMemoryAllocator.h.
|
inlineexplicitprotected |
Definition at line 92 of file AlignedMemoryAllocator.h.
|
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 244 of file MemoryAllocator.cc.
|
overridevirtual |
NOTE: Normally the _mm_alloc() and _mm_free() functions allow allocating aligned memory. It should be checked if they are available everywhere.
Implements Arcane::IMemoryAllocator.
Definition at line 147 of file MemoryAllocator.cc.
|
inlinestatic |
Allocator guaranteeing alignment to a cache line.
Definition at line 85 of file AlignedMemoryAllocator.h.
|
inlinestaticconstexpr |
Alignment for a cache line.
Definition at line 68 of file AlignedMemoryAllocator.h.
|
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.
Definition at line 185 of file MemoryAllocator.cc.
References Arcane::AllocatedMemoryInfo::baseAddress().
|
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 103 of file AlignedMemoryAllocator.h.
|
inlineoverridevirtual |
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 98 of file AlignedMemoryAllocator.h.
|
inlineoverridevirtual |
Memory resource provided by the allocator.
Reimplemented from Arcane::IMemoryAllocator.
Definition at line 104 of file AlignedMemoryAllocator.h.
References Arcane::Host.
|
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():
Implements Arcane::IMemoryAllocator.
Definition at line 168 of file MemoryAllocator.cc.
References Arcane::AllocatedMemoryInfo::baseAddress().
|
inlinestatic |
Allocator guaranteeing alignment to use vectorization on the target platform.
This is the alignment for the more restrictive type, and therefore this allocator can be used for all vector structures.
Definition at line 77 of file AlignedMemoryAllocator.h.
|
inlinestaticconstexpr |
Alignment for structures using vectorization.
Definition at line 66 of file AlignedMemoryAllocator.h.