Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
DefaultMemoryAllocator.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* DefaultMemoryAllocator.h (C) 2000-2025 */
9/* */
10/* Default memory allocator. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_DEFAULTMEMORYALLOCATOR_H
13#define ARCCORE_COMMON_DEFAULTMEMORYALLOCATOR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/IMemoryAllocator.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*!
29 * \brief Memory allocator via malloc/realloc/free.
30 *
31 * TODO: mark methods as 'final'.
32 */
33class ARCCORE_COMMON_EXPORT DefaultMemoryAllocator
34: public IMemoryAllocator
35{
36 friend class ArrayMetaData;
37
38 private:
39
40 static DefaultMemoryAllocator shared_null_instance;
41
42 public:
43
44 bool hasRealloc(MemoryAllocationArgs) const override;
48 Int64 adjustedCapacity(MemoryAllocationArgs, Int64 wanted_capacity, Int64 element_size) const override;
49 size_t guaranteedAlignment(MemoryAllocationArgs) const override { return 0; }
51};
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
56/*!
57 * \brief Memory allocator via malloc/realloc/free with listing output.
58 *
59 * This allocator is primarily used for debugging purposes.
60 * Information output is done via std::cout.
61 */
62class ARCCORE_COMMON_EXPORT PrintableMemoryAllocator
64{
65 using Base = DefaultMemoryAllocator;
66
67 public:
68
72
73 public:
74
78};
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83} // namespace Arcane
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88#endif
Information about an allocated memory region.
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.
size_t guaranteedAlignment(MemoryAllocationArgs) const override
Value of the alignment guaranteed by the allocator.
Int64 adjustedCapacity(MemoryAllocationArgs, Int64 wanted_capacity, Int64 element_size) const override
Adjusts the capacity based on the element size.
eMemoryResource memoryResource() const override
Memory resource provided by the allocator.
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 deallocate(MemoryAllocationArgs args, AllocatedMemoryInfo ptr)=0
Frees the memory whose base address is ptr.
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.
Class containing information to specialize allocations.
Memory allocator via malloc/realloc/free with listing output.
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.
eMemoryResource
List of available memory resources.
@ Host
Allocates on the host.