Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MemoryPool.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/* MemoryPool.h (C) 2000-2026 */
9/* */
10/* Class to manage a list of allocated zones. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_INTERNAL_MEMORYPOOL_H
13#define ARCCORE_COMMON_INTERNAL_MEMORYPOOL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/IMemoryPool.h"
18
19#include <memory>
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Impl
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
39class ARCCORE_COMMON_EXPORT IMemoryPoolAllocator
40{
41 public:
42
43 virtual ~IMemoryPoolAllocator() = default;
44
45 public:
46
48 virtual void* allocateMemory(Int64 size) = 0;
50 virtual void freeMemory(void* address, Int64 size) = 0;
51};
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
65class ARCCORE_COMMON_EXPORT MemoryPool
66: public IMemoryPool
68{
69 class Impl;
70
71 public:
72
73 explicit MemoryPool(IMemoryPoolAllocator* allocator, const String& name);
74 ~MemoryPool() override;
75
76 public:
77
78 MemoryPool(const MemoryPool&) = delete;
79 MemoryPool(MemoryPool&&) = delete;
80 MemoryPool& operator=(const MemoryPool&) = delete;
81 MemoryPool& operator=(MemoryPool&&) = delete;
82
83 public:
84
85 void* allocateMemory(Int64 size) override;
86 void freeMemory(void* ptr, Int64 size) override;
87 void dumpStats(std::ostream& ostr);
88 void dumpFreeMap(std::ostream& ostr);
89 String name() const;
90
92
93 void setMaxCachedBlockSize(Int32 v) override;
94 void freeCachedMemory() override;
95 Int64 totalAllocated() const override;
96 Int64 totalCached() const override;
98
99 private:
100
101 std::unique_ptr<Impl> m_p;
102};
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107} // namespace Arcane::Impl
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112#endif
Interface of a memory pool.
Definition IMemoryPool.h:32
Interface for an allocator for a MemoryPool.
Definition MemoryPool.h:40
virtual void freeMemory(void *address, Int64 size)=0
Frees the block located at address address containing size bytes.
virtual void * allocateMemory(Int64 size)=0
Allocates a block for size bytes.
void setMaxCachedBlockSize(Int32 v) override
Implementation of IMemoryPool.
void freeMemory(void *ptr, Int64 size) override
Frees the block located at address address containing size bytes.
void * allocateMemory(Int64 size) override
Allocates a block for size bytes.
Int64 totalAllocated() const override
Total size (in bytes) allocated in the memory pool.
void freeCachedMemory() override
Frees the memory in the cache.
Int64 totalCached() const override
Total size (in bytes) in the cache.
std::int64_t Int64
Signed integer type of 64 bits.
std::int32_t Int32
Signed integer type of 32 bits.