66 * PROGRAMMER: Peter Geinitz (Wayfarer)
77 */
88
9+ using System ;
10+
911namespace MemoryManager . Core
1012{
1113 /// <summary>
1214 /// The config for the mm
1315 /// </summary>
1416 public sealed class MemoryManagerConfig
1517 {
16-
1718 /// <summary>
1819 /// Parameter-less constructor with defaults
1920 /// </summary>
@@ -50,8 +51,22 @@ public MemoryManagerConfig(int slowLaneSize)
5051 // Default hybrid tuning
5152 SlowLaneBlobCapacityFraction = 0.20 ;
5253 SlowLaneBlobThreshold = 256 ;
54+
55+ // Default performance-tuned layout choices
56+ FastLaneFreeListStrategy = AllocationStrategy . FirstFit ;
57+ SlowLaneFreeListStrategy = AllocationStrategy . BestFit ;
5358 }
5459
60+ /// <summary>
61+ /// Gets the free-list block search strategy used by the FastLane when running the FreeList strategy wrapper.
62+ /// </summary>
63+ public AllocationStrategy FastLaneFreeListStrategy { get ; init ; } = AllocationStrategy . FirstFit ;
64+
65+ /// <summary>
66+ /// Gets the free-list block search strategy used by the SlowLane to manage gap allocations.
67+ /// </summary>
68+ public AllocationStrategy SlowLaneFreeListStrategy { get ; init ; } = AllocationStrategy . BestFit ;
69+
5570 /// <summary>
5671 /// Gets the fast lane strategy.
5772 /// Your pick old FastLane or the more speedy BumbLane.
@@ -199,12 +214,11 @@ public MemoryManagerConfig(int slowLaneSize)
199214 public int SlowLaneBlobThreshold { get ; init ; } = 256 ;
200215
201216 /// <summary>
202- /// Estimates the total reserved unmanaged memory (in bytes) this configuration will request,
203- /// not including minor overhead for handles and management structures.
217+ /// Estimates the total reserved unmanaged memory (in bytes) this configuration will request,
218+ /// not including minor overhead for handles and management structures.
204219 /// </summary>
205220 public double GetEstimatedReservedMegabytes ( )
206221 {
207- // BufferSize is gone! Just the raw unmanaged lane allocations.
208222 return ( FastLaneSize + SlowLaneSize ) / ( 1024.0 * 1024.0 ) ;
209223 }
210224
@@ -213,28 +227,35 @@ public double GetEstimatedReservedMegabytes()
213227 */
214228
215229 /// <summary>
216- /// Creates a configuration tuned for real-time game loops.
230+ /// Creates a configuration tuned for real-time game loops.
217231 /// Employs an ultra-fast Bump/Linear allocator for short-lived transient frames.
218232 /// </summary>
233+ /// <param name="totalBudget">The total budget.</param>
234+ /// <returns>MemoryManagerConfig instance configured for real-time game loops.</returns>
219235 public static MemoryManagerConfig CreateForGameLoop ( int totalBudget = 16 * 1024 * 1024 )
220236 {
221237 return new MemoryManagerConfig
222238 {
223239 SlowLaneSize = ( int ) ( totalBudget * 0.75 ) ,
224240 FastLaneSize = ( int ) ( totalBudget * 0.25 ) ,
225241 FastLaneStrategy = AllocatorStrategy . LinearBump , // Maximum speed
226- MaxFastLaneAgeFrames = 300 , // Evict to SlowLane faster
242+ MaxFastLaneAgeFrames = 300 , // Evict to SlowLane faster
227243 FastLaneUsageThreshold = 0.85 ,
228244 CompactionThreshold = 0.75 ,
229245 EnableAutoCompaction = true ,
230- PolicyCheckInterval = TimeSpan . FromMilliseconds ( 16 ) // Check roughly every frame at 60fps
246+ PolicyCheckInterval = TimeSpan . FromMilliseconds ( 16 ) , // Check roughly every frame at 60fps
247+
248+ // Homogeneous loop presets: SlowLane aggregates long-lived chunks neatly via BestFit
249+ SlowLaneFreeListStrategy = AllocationStrategy . BestFit
231250 } ;
232251 }
233252
234253 /// <summary>
235254 /// Creates a configuration tuned for heavy I/O, networking, or asset streaming.
236255 /// Uses a FreeList allocator to handle random out-of-order allocations.
237256 /// </summary>
257+ /// <param name="totalBudget">The total budget.</param>
258+ /// <returns>MemoryManagerConfig instance configured for bulk processing.</returns>
238259 public static MemoryManagerConfig CreateForBulkProcessing ( int totalBudget = 64 * 1024 * 1024 )
239260 {
240261 return new MemoryManagerConfig
@@ -246,27 +267,36 @@ public static MemoryManagerConfig CreateForBulkProcessing(int totalBudget = 64 *
246267 MaxFastLaneAgeFrames = 1200 , // Let data sit longer before moving
247268 SlowLaneUsageThreshold = 0.80 ,
248269 SlowLaneBlobThreshold = 512 , // Route larger fragments to blobs
249- PolicyCheckInterval = TimeSpan . FromSeconds ( 2 ) // Low maintenance overhead
270+ PolicyCheckInterval = TimeSpan . FromSeconds ( 2 ) , // Low maintenance overhead
271+
272+ // Heterogeneous presets: prioritize high allocation velocity on FastLane, anti-fragmentation on SlowLane
273+ FastLaneFreeListStrategy = AllocationStrategy . FirstFit ,
274+ SlowLaneFreeListStrategy = AllocationStrategy . BestFit
250275 } ;
251276 }
252277
253278 /// <summary>
254279 /// Creates a configuration tuned for tightly constrained or embedded footprints.
255280 /// Minimizes unmanaged allocation limits and compacts aggressively.
256281 /// </summary>
282+ /// <returns>MemoryManagerConfig instance configured for low memory scenarios.</returns>
257283 public static MemoryManagerConfig CreateForLowMemory ( )
258284 {
259285 return new MemoryManagerConfig
260286 {
261- FastLaneSize = 256 * 1024 , // 256 KB
262- SlowLaneSize = 1024 * 1024 , // 1 MB
287+ FastLaneSize = 256 * 1024 , // 256 KB
288+ SlowLaneSize = 1024 * 1024 , // 1 MB
263289 FastLaneStrategy = AllocatorStrategy . FreeList ,
264290 EnableAutoCompaction = true ,
265291 CompactionThreshold = 0.60 , // Compact very early
266292 FastLaneUsageThreshold = 0.70 ,
267293 SlowLaneUsageThreshold = 0.70 ,
268294 SlowLaneBlobCapacityFraction = 0.35 , // Allocate more space for tiny fragments
269- PolicyCheckInterval = TimeSpan . FromMilliseconds ( 500 )
295+ PolicyCheckInterval = TimeSpan . FromMilliseconds ( 500 ) ,
296+
297+ // Low-Footprint presets: Use BestFit everywhere to squeeze the max data out of limited space limits
298+ FastLaneFreeListStrategy = AllocationStrategy . BestFit ,
299+ SlowLaneFreeListStrategy = AllocationStrategy . BestFit
270300 } ;
271301 }
272302 }
0 commit comments