Skip to content

Commit

Permalink
Merge branch 'perf/arraypool-game-movestack' into perf/arraypool-all
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Sep 10, 2024
2 parents b5c6499 + e647038 commit 95634ea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Lynx/Model/Game.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NLog;
using System.Buffers;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace Lynx.Model;
Expand Down Expand Up @@ -41,7 +43,9 @@ public Game(ReadOnlySpan<char> fen, ReadOnlySpan<char> rawMoves, Span<Range> ran

PositionHashHistory = new(Constants.MaxNumberMovesInAGame) { CurrentPosition.UniqueIdentifier };
HalfMovesWithoutCaptureOrPawnMove = parsedFen.HalfMoveClock;
_moveStack = new Move[1024];

Debug.Assert(Constants.MaxNumberMovesInAGame <= 1024, "Need to customized ArrayPool due to desired array size requirements");
_moveStack = ArrayPool<Move>.Shared.Rent(Constants.MaxNumberMovesInAGame);

#if DEBUG
MoveHistory = new(Constants.MaxNumberMovesInAGame);
Expand Down Expand Up @@ -231,6 +235,8 @@ public void UpdateInitialPosition()

public void FreeResources()
{
ArrayPool<Move>.Shared.Return(_moveStack);

CurrentPosition.FreeResources();
PositionBeforeLastSearch.FreeResources();
}
Expand Down

0 comments on commit 95634ea

Please sign in to comment.