hlsf wrong alloc solved

This commit is contained in:
Youmu Liu
2025-11-24 17:00:10 +08:00
parent 67a4ac385f
commit b7b960a604
12 changed files with 357 additions and 290 deletions
@@ -38,6 +38,21 @@ namespace StgSharp.HighPerformance.Memory
public unsafe partial class HybridLayerSegregatedFitAllocator
{
/// <summary>
/// check out if a bucket is within the same higher-level boundary as currentOffset
/// </summary>
/// <param name="currentOffset">
///
/// </param>
/// <param name="target">
///
/// </param>
/// <param name="level">
///
/// </param>
/// <returns>
///
/// </returns>
private bool AssertBackwardBoundary(ulong currentOffset, Entry* target, int level)
{
int nextLevelSize = levelSizeArray[level] * 4;
@@ -45,6 +60,21 @@ namespace StgSharp.HighPerformance.Memory
return (currentOffset / (ulong)nextLevelSize) == (targetHead / (ulong)nextLevelSize);
}
/// <summary>
/// check out if a bucket is within the same higher-level boundary as currentOffset
/// </summary>
/// <param name="currentOffset">
///
/// </param>
/// <param name="target">
///
/// </param>
/// <param name="level">
///
/// </param>
/// <returns>
///
/// </returns>
private bool AssertForwardBoundary(ulong currentOffset, Entry* target, int level)
{
int nextLevelSize = levelSizeArray[level] * 4;
@@ -75,7 +105,7 @@ namespace StgSharp.HighPerformance.Memory
/// <summary>
/// Used in Free operations, efficiently remove from buckets and merge adjacent blocks.
/// Current Entry will serve as the final merged block. The Merge will be in lazy
/// strategy, any fail in acquiring spin lock will end a merging process.
/// strategy.
/// </summary>
private void MergeAndRemoveFromBuckets(Entry* entry)
{
@@ -99,8 +129,7 @@ namespace StgSharp.HighPerformance.Memory
ulong p = entry->PreviousNear;
Entry* prev = (Entry*)p;
// 计算当前块相对于分配空间基址的偏移量
// compute offset of current block and base position
ulong currentOffset = entry->Position - (ulong)m_Buffer;
if (prev == null ||