Blender
V4.3
source
blender
blenlib
intern
memory_counter.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2024 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#include "
BLI_memory_counter.hh
"
6
7
namespace
blender::memory_counter
{
8
9
MemoryCounter::MemoryCounter
(
MemoryCount
&
count
) : count_(
count
) {}
10
11
void
MemoryCounter::add
(
const
int64_t
bytes)
12
{
13
count_.
total_bytes
+= bytes;
14
}
15
16
void
MemoryCounter::add_shared
(
const
ImplicitSharingInfo
*sharing_info,
17
const
FunctionRef
<
void
(
MemoryCounter
&memory)> count_fn)
18
{
19
if
(!sharing_info) {
20
/* Data is not actually shared. */
21
count_fn(*
this
);
22
return
;
23
}
24
if
(!count_.
handled_shared_data
.add_as(sharing_info)) {
25
/* Data was counted before, avoid counting it again. */
26
return
;
27
}
28
sharing_info->
add_weak_user
();
29
/* Count into the `this` for now. In the future we could pass in a separate #MemoryCounter here
30
* if we needed to know the amount of memory used by each shared data. */
31
count_fn(*
this
);
32
}
33
34
void
MemoryCounter::add_shared
(
const
ImplicitSharingInfo
*sharing_info,
const
int64_t
bytes)
35
{
36
this->
add_shared
(sharing_info, [&](
MemoryCounter
&shared_memory) { shared_memory.
add
(bytes); });
37
}
38
39
void
MemoryCount::reset
()
40
{
41
std::destroy_at(
this
);
42
new
(
this
)
MemoryCount
();
43
}
44
45
}
// namespace blender::memory_counter
BLI_memory_counter.hh
blender::FunctionRef
Definition
BLI_function_ref.hh:74
blender::ImplicitSharingInfo
Definition
BLI_implicit_sharing.hh:41
blender::ImplicitSharingInfo::add_weak_user
void add_weak_user() const
Definition
BLI_implicit_sharing.hh:102
blender::memory_counter::MemoryCount
Definition
BLI_memory_counter.hh:20
blender::memory_counter::MemoryCount::handled_shared_data
Set< WeakImplicitSharingPtr > handled_shared_data
Definition
BLI_memory_counter.hh:31
blender::memory_counter::MemoryCount::total_bytes
int64_t total_bytes
Definition
BLI_memory_counter.hh:29
blender::memory_counter::MemoryCount::reset
void reset()
Definition
memory_counter.cc:39
blender::memory_counter::MemoryCounter
Definition
BLI_memory_counter.hh:41
blender::memory_counter::MemoryCounter::add
void add(const int64_t bytes)
Definition
memory_counter.cc:11
blender::memory_counter::MemoryCounter::add_shared
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
blender::memory_counter::MemoryCounter::MemoryCounter
MemoryCounter(MemoryCount &count)
Definition
memory_counter.cc:9
count
int count
Definition
interface_widgets.cc:1056
blender::memory_counter
Definition
BLI_memory_counter.hh:18
int64_t
__int64 int64_t
Definition
stdint.h:89
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0