Arcane  v4.1.1.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
31namespace impl
32{
33 //! Calcule une capacité adaptée pour une taille de \a size
34 extern "C++" ARCANE_UTILS_EXPORT Int64
36} // namespace impl
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40/*!
41 * \brief Redimensionne un tableau en ajoutant une réserve de mémoire.
42 *
43 * Le tableau \a array est redimensionné uniquement si \a new_size est
44 * supérieure à la taille actuelle du tableau ou si \a force_resize est vrai.
45 *
46 * Si le tableau est redimensionné, on réserve une capacité supplémentaire
47 * pour éviter de réallouer à chaque fois.
48 *
49 * \retval 2 si on a réalloué via reserve()
50 * \retval 1 si on a re-dimensionné sans réallouer.
51 * \retval 0 si aucune opération n'a eu lieu.
52 */
53template <typename DataType> inline Int32
54checkResizeArrayWithCapacity(Array<DataType>& array, Int64 new_size, bool force_resize)
55{
56 Int32 ret_value = 0;
57 Int64 s = array.largeSize();
58 if (new_size > s || force_resize) {
59 ret_value = 1;
60 if (new_size > array.capacity()) {
61 array.reserve(impl::computeCapacity(new_size));
62 ret_value = 2;
63 }
64 array.resize(new_size);
65 }
66 return ret_value;
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71/*!
72 * \brief Redimensionne un tableau en ajoutant une réserve de mémoire.
73 *
74 * Cet appel est équivalent à checkResizeArrayWithCapacity(array, new_size, false).
75 */
76template <typename DataType> inline Int32
77checkResizeArrayWithCapacity(Array<DataType>& array, Int64 new_size)
78{
79 return checkResizeArrayWithCapacity(array, new_size, false);
80}
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85} // namespace Arcane::MemoryUtils
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90#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:54
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.