Blender V4.3
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
6
8
10
11void MemoryCounter::add(const int64_t bytes)
12{
13 count_.total_bytes += bytes;
14}
15
16void 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
34void 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
40{
41 std::destroy_at(this);
42 new (this) MemoryCount();
43}
44
45} // namespace blender::memory_counter
Set< WeakImplicitSharingPtr > handled_shared_data
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
int count
__int64 int64_t
Definition stdint.h:89