Add allocator tag support for Dictionary and HashSet

This commit is contained in:
Wojtek Figat
2025-07-07 23:22:32 +02:00
parent 48c6339ebb
commit a8eb4fc140
4 changed files with 25 additions and 1 deletions

View File

@@ -163,6 +163,15 @@ public:
{
}
/// <summary>
/// Initializes an empty <see cref="Dictionary"/> without reserving any space.
/// </summary>
/// <param name="tag">The custom allocation tag.</param>
Dictionary(typename Base::AllocationTag tag)
: Base(tag)
{
}
/// <summary>
/// Initializes <see cref="Dictionary"/> by reserving space.
/// </summary>

View File

@@ -140,6 +140,15 @@ public:
{
}
/// <summary>
/// Initializes an empty <see cref="HashSet"/> without reserving any space.
/// </summary>
/// <param name="tag">The custom allocation tag.</param>
HashSet(typename Base::AllocationTag tag)
: Base(tag)
{
}
/// <summary>
/// Initializes <see cref="HashSet"/> by reserving space.
/// </summary>

View File

@@ -59,6 +59,7 @@ class HashSetBase
public:
// Type of allocation data used to store hash set buckets.
using AllocationData = typename AllocationType::template Data<BucketType>;
using AllocationTag = typename AllocationType::Tag;
protected:
int32 _elementsCount = 0;
@@ -70,6 +71,11 @@ protected:
{
}
HashSetBase(AllocationTag tag)
: _allocation(tag)
{
}
void MoveToEmpty(HashSetBase&& other)
{
_elementsCount = other._elementsCount;

View File

@@ -138,7 +138,7 @@ public:
FORCE_INLINE void Swap(Data& other)
{
::Swap(_data, other._data);
::Swap(_arena, other._arena);
_arena = other._arena; // TODO: find a better way to move allocation with AllocationUtils::MoveToEmpty to preserve/maintain allocation tag ownership
}
};
};