Arcane  v4.1.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
MemoryUtils.h
Aller à la documentation de ce fichier.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* MemoryUtils.h (C) 2000-2025 */
9/* */
10/* Fonctions utilitaires de gestion mémoire. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_MEMORYUTILS_H
13#define ARCANE_UTILS_MEMORYUTILS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include "arccore/common/MemoryAllocationArgs.h"
20#include "arccore/common/MemoryUtils.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::MemoryUtils
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30/*!
31 * \brief Allocateur spécifique pour les accélérateurs.
32 *
33 * \deprecated Use MemoryUtils::getDefaultDataAllocator() instead.
34 */
35extern "C++" ARCANE_DEPRECATED_REASON("Y2024: Use getDefaultDataAllocator() instead.")
36ARCANE_UTILS_EXPORT IMemoryAllocator*
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42namespace impl
43{
44 //! Calcule une capacité adaptée pour une taille de \a size
45 extern "C++" ARCANE_UTILS_EXPORT Int64
46 computeCapacity(Int64 size);
47} // namespace impl
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51/*!
52 * \brief Redimensionne un tableau en ajoutant une réserve de mémoire.
53 *
54 * Le tableau \a array est redimensionné uniquement si \a new_size est
55 * supérieure à la taille actuelle du tableau ou si \a force_resize est vrai.
56 *
57 * Si le tableau est redimensionné, on réserve une capacité supplémentaire
58 * pour éviter de réallouer à chaque fois.
59 *
60 * \retval 2 si on a réalloué via reserve()
61 * \retval 1 si on a re-dimensionné sans réallouer.
62 * \retval 0 si aucune opération n'a eu lieu.
63 */
64template <typename DataType> inline Int32
65checkResizeArrayWithCapacity(Array<DataType>& array, Int64 new_size, bool force_resize)
66{
67 Int32 ret_value = 0;
68 Int64 s = array.largeSize();
69 if (new_size > s || force_resize) {
70 ret_value = 1;
71 if (new_size > array.capacity()) {
72 array.reserve(impl::computeCapacity(new_size));
73 ret_value = 2;
74 }
75 array.resize(new_size);
76 }
77 return ret_value;
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82/*!
83 * \brief Redimensionne un tableau en ajoutant une réserve de mémoire.
84 *
85 * Cet appel est équivalent à checkResizeArrayWithCapacity(array, new_size, false).
86 */
87template <typename DataType> inline Int32
88checkResizeArrayWithCapacity(Array<DataType>& array, Int64 new_size)
89{
90 return checkResizeArrayWithCapacity(array, new_size, false);
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96} // namespace Arcane::MemoryUtils
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101#endif
Int64 computeCapacity(Int64 size)
Calcule une capacité adaptée pour une taille de size.
Déclarations des types utilisés dans Arcane.
Espace de noms pour les fonctions de gestion mémoire et des allocateurs.
Int32 checkResizeArrayWithCapacity(Array< DataType > &array, Int64 new_size, bool force_resize)
Redimensionne un tableau en ajoutant une réserve de mémoire.
Definition MemoryUtils.h:65
IMemoryAllocator * getAcceleratorHostMemoryAllocator()
Allocateur spécifique pour les accélérateurs.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.