Blender V5.0
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
10
12
14
15void MemoryCounter::add(const int64_t bytes)
16{
17 count_.total_bytes += bytes;
18}
19
20void 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
38void 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
44{
45 std::destroy_at(this);
46 new (this) MemoryCount();
47}
48
49} // namespace blender::memory_counter
long long int int64_t
Set< WeakImplicitSharingPtr > handled_shared_data
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
int count