Blender
V5.0
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
8
9
#include "
BLI_memory_counter.hh
"
10
11
namespace
blender::memory_counter
{
12
13
MemoryCounter::MemoryCounter
(
MemoryCount
&
count
) : count_(
count
) {}
14
15
void
MemoryCounter::add
(
const
int64_t
bytes)
16
{
17
count_.total_bytes += bytes;
18
}
19
20
void
MemoryCounter::add_shared
(
const
ImplicitSharingInfo
*sharing_info,
21
const
FunctionRef
<
void
(
MemoryCounter
&memory)> count_fn)
22
{
23
if
(!sharing_info) {
24
/* Data is not actually shared. */
25
count_fn(*
this
);
26
return
;
27
}
28
if
(!count_.
handled_shared_data
.add_as(sharing_info)) {
29
/* Data was counted before, avoid counting it again. */
30
return
;
31
}
32
sharing_info->
add_weak_user
();
33
/* Count into the `this` for now. In the future we could pass in a separate #MemoryCounter here
34
* if we needed to know the amount of memory used by each shared data. */
35
count_fn(*
this
);
36
}
37
38
void
MemoryCounter::add_shared
(
const
ImplicitSharingInfo
*sharing_info,
const
int64_t
bytes)
39
{
40
this->
add_shared
(sharing_info, [&](
MemoryCounter
&shared_memory) { shared_memory.
add
(bytes); });
41
}
42
43
void
MemoryCount::reset
()
44
{
45
std::destroy_at(
this
);
46
new
(
this
)
MemoryCount
();
47
}
48
49
}
// namespace blender::memory_counter
BLI_memory_counter.hh
int64_t
long long int int64_t
Definition
btConvexHullComputer.cpp:31
blender::FunctionRef
Definition
BLI_function_ref.hh:72
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:18
blender::memory_counter::MemoryCount::handled_shared_data
Set< WeakImplicitSharingPtr > handled_shared_data
Definition
BLI_memory_counter.hh:29
blender::memory_counter::MemoryCount::reset
void reset()
Definition
memory_counter.cc:43
blender::memory_counter::MemoryCounter
Definition
BLI_memory_counter.hh:39
blender::memory_counter::MemoryCounter::add
void add(const int64_t bytes)
Definition
memory_counter.cc:15
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:13
count
int count
Definition
interface_widgets.cc:1067
blender::memory_counter
Definition
BLI_memory_counter.hh:16
Generated on
for Blender by
doxygen
1.16.1