Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
arcane/src/arcane/utils/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/*---------------------------------------------------------------------------*/
35extern "C++" ARCANE_DEPRECATED_REASON("Y2024: Use getDefaultDataAllocator() instead.")
36ARCANE_UTILS_EXPORT IMemoryAllocator*
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42namespace impl
43{
45 extern "C++" ARCANE_UTILS_EXPORT Int64
46 computeCapacity(Int64 size);
47} // namespace impl
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
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/*---------------------------------------------------------------------------*/
87template <typename DataType> inline Int32
89{
90 return checkResizeArrayWithCapacity(array, new_size, false);
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96} // namespace Arcane::MemoryUtils
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101#endif
Déclarations des types utilisés dans Arcane.
Int64 computeCapacity(Int64 size)
Calcule une capacité adaptée pour une taille de size.
Integer capacity() const
Capacité (nombre d'éléments alloués) du vecteur.
Int64 largeSize() const
Nombre d'éléments du vecteur (en 64 bits)
Tableau d'items de types quelconques.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
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.
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.