UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMWeakKeyMap.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
7#include "Containers/Map.h"
8
9namespace Verse
10{
11
12struct FMarkStack;
13struct VCell;
14
15// This is a collection of "transposed" weak maps.
16//
17// A transposed weak map maps maps to values. I.e. while a weak map is a Key -> Value map, a transposed weak map
18// is a Map -> Value map.
19//
20// A weak key map is a collection of transposed weak maps keyed by key. I.e. a weak key map is a Key -> Map -> Value
21// map.
22//
23// For every weak map entry in the world of the form Key -> Value where Map is the owning map (the one that would do
24// the logic in VisitReferences that says "if Key is marked then mark Value"), there must be a weak key map entry
25// of the form Key -> Map -> Value. This ensures that if Key is not yet marked before the Map runs its
26// VisitReferences, then the weak key map that owns the Key will do the marking by running "if Map is marked then
27// mark Value" logic.
28//
29// You could imagine there being one FWeakKeyMap globally for the whole GC. That would work. But we hang FWeakKeyMap
30// off libpas's verse_heap_page_header (aka Verse::FHeapPageHeader). There is one of those per "page" for objects
31// in segregated storage, and one globally for all large objects. Libpas manages the synchronization that protects
32// these maps.
33//
34// Most of this is "owned" by VCell. VCell accesses this via FWeakKeyMapGuard.
35struct FWeakKeyMap final
36{
39
40 bool IsEmpty() const
41 {
42 return InternalMap.IsEmpty();
43 }
44
45 // This is just to support testing.
46 bool HasEntriesForKey(VCell* Key) const;
47
48 void Add(VCell* Key, VCell* Map, VCell* Value);
49 void Remove(VCell* Key, VCell* Map);
50
51 template <typename TVisitor>
52 void Visit(VCell* Key, TVisitor& Visitor);
53
54 void ConductCensus();
55
56 size_t GetAllocatedSize() const
57 {
58 return InternalMap.GetAllocatedSize();
59 }
60
61private:
63};
64
65} // namespace Verse
66#endif // WITH_VERSE_VM
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
decltype(auto) Visit(Func &&Callable, Variants &&... Args)
Definition TVariant.h:271
Definition UnrealString.h.inl:34
SIZE_T GetAllocatedSize(const T &Value)
Definition ManagedArray.h:93
Definition Archive.h:36