Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TestMemoryPool.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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#include <gtest/gtest.h>
9
10#include "arcane/utils/internal/MemoryPool.h"
11#include "arcane/utils/String.h"
12
13/*---------------------------------------------------------------------------*/
14/*---------------------------------------------------------------------------*/
15
16using namespace Arcane;
17using namespace Arcane::impl;
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
24{
25 void* allocateMemory(size_t size) override { return std::malloc(size); }
26 void freeMemory(void* address,size_t) override { std::free(address); }
27};
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32TEST(MemoryPool, Misc)
33{
35 MemoryPool memory_pool(&my_allocator, "MyMemoryPool");
36 size_t max_block_size = 1024 * 8;
37 memory_pool.setMaxCachedBlockSize(1024 * 8);
38
39 void* a1 = memory_pool.allocateMemory(25);
40 void* a2 = memory_pool.allocateMemory(47);
41 memory_pool.freeMemory(a1, 25);
42 memory_pool.freeMemory(a2, 47);
43 void* a3 = memory_pool.allocateMemory(25);
44 memory_pool.dumpStats(std::cout);
45 memory_pool.dumpFreeMap(std::cout);
46 memory_pool.freeMemory(a3, 25);
47
48 void* a4 = memory_pool.allocateMemory(max_block_size * 2);
49 memory_pool.freeMemory(a4, max_block_size * 2);
50
51 std::cout << "End Of Test\n";
52 memory_pool.dumpStats(std::cout);
53 memory_pool.dumpFreeMap(std::cout);
54 memory_pool.freeCachedMemory();
55}
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Interface d'un allocateur pour un MemoryPool.
Definition MemoryPool.h:39
Classe pour gérer une liste de zone allouées.
Definition MemoryPool.h:65
void freeMemory(void *address, size_t) override
Libère le bloc situé à l'adresse address contenant size octets.
void * allocateMemory(size_t size) override
Alloue un bloc pour size octets.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-