Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
LazyMemoryPool.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/* LazyMemoryPool.h (C) 2000-2026 */
9/* */
10/* Zero buffers shared by the connectivities that are still lazy. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MESH_INTERNAL_LAZYMEMORYPOOL_H
13#define ARCANE_MESH_INTERNAL_LAZYMEMORYPOOL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18
19#include <memory>
20#include <mutex>
21#include <vector>
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane::mesh
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
51{
52 public:
53
55 struct Buffer
56 {
57 Buffer();
58 UniqueArray<Int32> m_zeros;
59 Int32 m_nb_reader = 0;
61 bool m_is_exact = false;
62 };
63
64 public:
65
68
71
73 void release(Buffer*& buffer);
74
75 private:
76
77 std::vector<std::unique_ptr<Buffer>> m_buffers;
78 std::mutex m_mutex;
79
80 private:
81
82 Buffer* _smallestBuffer(Int32 n, bool only_exact);
83 Buffer* _addBuffer(Int32 size, bool is_exact);
84 ConstArrayView<Int32> _moveTo(Buffer*& buffer, Buffer* new_buffer);
85 void _release(Buffer*& buffer);
86};
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91} // namespace Arcane::mesh
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96#endif
Constant view of an array of type T.
1D data vector with value semantics (STL style).
Zeros backing every lazy connectivity view of the process.
ConstArrayView< Int32 > _moveTo(Buffer *&buffer, Buffer *new_buffer)
Moves the reader of buffer to new_buffer.
ConstArrayView< Int32 > grow(Buffer *&buffer, Int32 n)
Moves buffer to a zero buffer of at least n elements if it is smaller.
ConstArrayView< Int32 > trim(Buffer *&buffer, Int32 n)
Moves buffer to the smallest exact buffer of at least n elements.
void release(Buffer *&buffer)
Stops reading buffer, and frees it if nothing else reads it.
std::int32_t Int32
Signed integer type of 32 bits.
One zero buffer and the number of connectivities reading it.
bool m_is_exact
Allocated by trim(), at the exact size asked.