Skip to content

Commit cdc89e1

Browse files
format
1 parent 93dc558 commit cdc89e1

19 files changed

Lines changed: 85 additions & 37 deletions

ExtendedSystemObjects/ImmutableLookupMapUnmanaged.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public ImmutableLookupMapUnmanaged(IDictionary<TKey, TValue> data)
125125
public void Dispose()
126126
{
127127
if (_disposed) return;
128+
128129
_entries.Dispose();
129130
_disposed = true;
130131
}

ExtendedSystemObjects/UnmanagedIntArray.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Runtime.CompilerServices;
1717
using ExtendedSystemObjects.Helper;
1818
using ExtendedSystemObjects.Interfaces;
19+
// ReSharper disable MemberCanBePrivate.Global
1920

2021
namespace ExtendedSystemObjects
2122
{
@@ -360,8 +361,9 @@ public void RemoveMultiple(ReadOnlySpan<int> indices)
360361
}
361362

362363
/// <summary>
363-
/// Returns a Span over the used portion of the array.
364+
/// Returns a Span over the used portion of the array.
364365
/// </summary>
366+
/// <returns>Dta as span.</returns>
365367
public Span<int> AsSpan()
366368
{
367369
EnsureNotDisposed();

ExtendedSystemObjects/UnmanagedMap.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ private List<TValue> GetValuesSnapshot()
166166
public void Dispose()
167167
{
168168
if (_disposed) return;
169+
169170
Free();
170171
GC.SuppressFinalize(this);
171172
_disposed = true;

MemoryManager.Core/MemoryManagerConfig.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public MemoryManagerConfig(int slowLaneSize)
5858
/// <summary>
5959
/// Gets the free-list block search strategy used by the FastLane when running the FreeList strategy wrapper.
6060
/// </summary>
61-
public AllocationStrategy FastLaneFreeListStrategy { get; init; } = AllocationStrategy.FirstFit;
61+
public AllocationStrategy FastLaneFreeListStrategy { get; private init; } = AllocationStrategy.FirstFit;
6262

6363
/// <summary>
6464
/// Gets the free-list block search strategy used by the SlowLane to manage gap allocations.
6565
/// </summary>
66-
public AllocationStrategy SlowLaneFreeListStrategy { get; init; } = AllocationStrategy.BestFit;
66+
public AllocationStrategy SlowLaneFreeListStrategy { get; private init; } = AllocationStrategy.BestFit;
6767

6868
/// <summary>
6969
/// Gets the fast lane strategy.
@@ -203,13 +203,13 @@ public MemoryManagerConfig(int slowLaneSize)
203203
/// Fraction of the SlowLane capacity dedicated to the BlobManager for small, unpredictable data.
204204
/// Example: 0.20 reserves 20% of the SlowLane for tiny blobs.
205205
/// </summary>
206-
public double SlowLaneBlobCapacityFraction { get; init; } = 0.20;
206+
public double SlowLaneBlobCapacityFraction { get; private init; } = 0.20;
207207

208208
/// <summary>
209209
/// Allocations in the SlowLane smaller than or equal to this size (in bytes)
210210
/// will be routed to the BlobManager instead of the main BlockManager.
211211
/// </summary>
212-
public int SlowLaneBlobThreshold { get; init; } = 256;
212+
public int SlowLaneBlobThreshold { get; private init; } = 256;
213213

214214
/// <summary>
215215
/// Estimates the total reserved unmanaged memory (in bytes) this configuration will request,
@@ -338,7 +338,8 @@ public static MemoryManagerConfig CreateForFrameScratch(int totalBudget = 8 * 10
338338
Threshold = totalBudget, // Guarantees ALL allocations up to the full budget hit FastLane!
339339
FastLaneStrategy = AllocatorStrategy.LinearBump, // Pure O(1) bump speed
340340
MaxFastLaneAgeFrames = 1, // Single-frame turnover
341-
EnableAutoCompaction = false, // Disabled: O(1) bump reset on Free handles cleanup, avoiding mid-frame stalls
341+
EnableAutoCompaction =
342+
false, // Disabled: O(1) bump reset on Free handles cleanup, avoiding mid-frame stalls
342343
FastLaneUsageThreshold = 0.99,
343344
SlowLaneUsageThreshold = 0.99
344345
};

MemoryManager.Lanes/LinearLane.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public unsafe LinearLane(int size, SlowLane slowLane, int maxEntries = 1024)
125125
public unsafe void Dispose()
126126
{
127127
if (_disposed) return;
128+
128129
_disposed = true;
129130

130131
// 1. Free main native buffer and reset pointer

MemoryManager.Lanes/SlabLane.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public bool CanAllocate(int size)
142142
{
143143
var binIndex = FindBinIndex(size);
144144
if (binIndex == -1) return false;
145+
145146
return _bins[binIndex].FreeCount > 0;
146147
}
147148

@@ -335,6 +336,7 @@ public int EstimateFragmentation()
335336
}
336337

337338
if (totalPhysicalActiveBytes == 0) return 0;
339+
338340
return (int)((double)(totalPhysicalActiveBytes - totalUserRequestedBytes) / totalPhysicalActiveBytes * 100);
339341
}
340342

@@ -368,6 +370,7 @@ public int GetAllocationSize(MemoryHandle handle) =>
368370
public IEnumerable<MemoryHandle> GetHandles()
369371
{
370372
if (_entries == null) yield break;
373+
371374
foreach (var id in _handleIndex.Keys)
372375
{
373376
if (_handleIndex.TryGetValue(id, out var index))

MemoryManager.Tests/ArenaBufferTests.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,39 @@
1111

1212
namespace MemoryManager.Tests
1313
{
14+
/// <summary>
15+
/// Simple Arena tests.
16+
/// </summary>
1417
[TestClass]
1518
public sealed class ArenaBufferTests
1619
{
17-
private MemoryArena _arena;
18-
20+
/// <summary>
21+
/// The arena
22+
/// </summary>
23+
private MemoryArena? _arena;
24+
25+
/// <summary>
26+
/// Setups this instance.
27+
/// </summary>
1928
[TestInitialize]
2029
public void Setup()
2130
{
2231
var config = MemoryManagerConfig.CreateForGameLoop(4 * 1024 * 1024);
2332
_arena = new MemoryArena(config);
2433
}
2534

35+
/// <summary>
36+
/// Cleanups this instance.
37+
/// </summary>
2638
[TestCleanup]
2739
public void Cleanup()
2840
{
2941
_arena?.Dispose();
3042
}
3143

44+
/// <summary>
45+
/// Arenas the buffer add and read validates data integrity.
46+
/// </summary>
3247
[TestMethod]
3348
public void ArenaBuffer_AddAndRead_ValidatesDataIntegrity()
3449
{
@@ -48,6 +63,9 @@ public void ArenaBuffer_AddAndRead_ValidatesDataIntegrity()
4863
}
4964
}
5065

66+
/// <summary>
67+
/// Arenas the buffer exceed capacity throws invalid operation exception.
68+
/// </summary>
5169
[TestMethod]
5270
public void ArenaBuffer_ExceedCapacity_ThrowsInvalidOperationException()
5371
{
@@ -60,6 +78,9 @@ public void ArenaBuffer_ExceedCapacity_ThrowsInvalidOperationException()
6078
Assert.ThrowsException<InvalidOperationException>(() => buffer.Add(4));
6179
}
6280

81+
/// <summary>
82+
/// Arenas the buffer clear resets count without reallocating.
83+
/// </summary>
6384
[TestMethod]
6485
public void ArenaBuffer_Clear_ResetsCountWithoutReallocating()
6586
{
@@ -78,6 +99,9 @@ public void ArenaBuffer_Clear_ResetsCountWithoutReallocating()
7899
Assert.AreEqual(300, buffer[0]);
79100
}
80101

102+
/// <summary>
103+
/// Arenas the buffer index out of bounds throws index out of range exception.
104+
/// </summary>
81105
[TestMethod]
82106
public void ArenaBuffer_IndexOutOfBounds_ThrowsIndexOutOfRangeException()
83107
{

MemoryManager.Tests/ArenaStackTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace MemoryManager.Tests
1414
[TestClass]
1515
public sealed class ArenaQueueTests
1616
{
17-
private MemoryArena _arena;
17+
private MemoryArena? _arena;
1818

1919
[TestInitialize]
2020
public void Setup()

MemoryManager.Tests/FrameScratchTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public void FrameScratch_NoSpillHint_SucceedsSeamlessly()
6565
using var arena = new MemoryArena(config);
6666

6767
// Rent with explicit NoSpill hint
68-
using var rent = new ArenaRent<int>(arena, 1024, hints: AllocationHints.FrameCritical | AllocationHints.NoSpill);
68+
using var rent = new ArenaRent<int>(arena, 1024,
69+
hints: AllocationHints.FrameCritical | AllocationHints.NoSpill);
6970
rent[0] = 123;
7071

7172
Assert.AreEqual(123, rent[0]);

MemoryManager.Tests/LinearLaneBugRegressionTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ public void MemoryArena_GameLoopPreset_PreventsBumpExhaustionViaArenaRent()
7272
// Should complete cleanly without spilling to SlowLane or throwing OutOfMemoryException
7373
for (var i = 0; i < totalIterations; i++)
7474
{
75-
using (var rent = new ArenaRent<int>(arena, rentElementCount))
76-
{
77-
rent[0] = i;
78-
rent[rentElementCount - 1] = i * 2;
79-
} // Dispose returns EntryCount to 0, triggering the bump offset reset
75+
using var rent = new ArenaRent<int>(arena, rentElementCount);
76+
rent[0] = i;
77+
rent[rentElementCount - 1] = i * 2;
8078
}
8179

8280
// Assert FastLane is back to zero active entries and ready for new frames

0 commit comments

Comments
 (0)