From 3aec45448c8af2cf331c8262466d4e2c5cf6f665 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 24 Aug 2014 22:50:21 +0000 Subject: [PATCH] TasMovie - TasStateManager - pre-allocate the SortedDictionary size based on state size and memory usage capacity. Fixes the problem of performance grinding to a halt as the movie frame count increases --- .../movie/tasproj/TasStateManager.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index bd15c705a5..399b481c65 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -21,6 +21,21 @@ namespace BizHawk.Client.Common { _movie = movie; Settings = new ManagerSettings(); + + var cap = Settings.Cap; + + int limit = 0; + if (Global.Emulator != null) + { + var stateSize = Global.Emulator.SaveStateBinary().Length; + + if (stateSize > 0) + { + limit = cap / stateSize; + } + } + + States = new SortedList(limit); } public ManagerSettings Settings { get; set; }