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
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="HLSFAllocator.BucketNode"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -55,6 +55,10 @@ namespace StgSharp.HighPerformance.Memory
{
_bucketHeads[index] = (nuint)node;
node->IsInBucket = true;
node->NextLevel = EmptyHandle;
node->PreviousLevel = EmptyHandle;
// Console.WriteLine($"Push to empty level of {levelIndex} {sizeIndex}, bucket pos {(ulong)node}");
return;
} else
{
@@ -62,7 +66,10 @@ namespace StgSharp.HighPerformance.Memory
node->NextLevel = head;
BucketNode* headNode = (BucketNode*)head;
node->IsInBucket = true;
if (headNode != null) {
// Console.WriteLine($"Push to head of level of {levelIndex} {sizeIndex}, bucket pos {(ulong)node}, previous head is at {head}");
if (headNode != null)
{
headNode->PreviousLevel = (ulong)node;
}
return;
@@ -111,6 +118,7 @@ namespace StgSharp.HighPerformance.Memory
return false;
}
// Console.WriteLine($"level popped from level {levelIndex} {sizeIndex}, node is at {(ulong)head}");
BucketNode* next = (BucketNode*)head->NextLevel;
if (next == null)
@@ -123,14 +131,8 @@ namespace StgSharp.HighPerformance.Memory
node = head;
node->IsInBucket = false;
node->NextLevel = EmptyHandle;
if (next != null)
{
Console.WriteLine("////////////// catching error ///////////////");
Console.WriteLine($"ref next: {(ulong)next}");
Console.WriteLine($"base pos: {(ulong)m_Buffer}");
Console.WriteLine(_size);
if (next != null) {
next->PreviousLevel = EmptyHandle;
Console.WriteLine("///////////// no error caught ///////////////");
}
return true;
}
@@ -157,6 +159,8 @@ namespace StgSharp.HighPerformance.Memory
node->NextLevel = EmptyHandle;
node->PreviousLevel = EmptyHandle;
node->IsInBucket = false;
return true;
}
@@ -164,30 +168,15 @@ namespace StgSharp.HighPerformance.Memory
/// BucketNode structure - specialized node for bucket linked lists Stored in main
/// allocation area (user-overwritable region)
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 40)]
[StructLayout(LayoutKind.Explicit)]
internal struct BucketNode
{
[FieldOffset(0)] internal Entry* EntryRef; // Pointer to corresponding Entry
[FieldOffset(32)] internal bool IsInBucket; // Whether in bucket
[FieldOffset(8)] internal ulong _nextLevel; // Bucket stack linked list: next pointer
[FieldOffset(16)] internal ulong LockBuffer;
[FieldOffset(24)] internal ulong PreviousLevel; // Bucket stack linked list: previous pointer
internal ulong NextLevel
{
get
{
Console.WriteLine($"get next level {_nextLevel}");
return _nextLevel;
}
set
{
Console.WriteLine($"NextLevel set to {value}.");
_nextLevel = value;
}
}
[FieldOffset(8)] internal ulong NextLevel; // Bucket stack linked list: next pointer
[FieldOffset(24)] internal ulong PreviousLevel; // Bucket stack linked list: previous pointer
}