/// <summary> /// Destroys the FlushableMemoryPool of the current thread. /// </summary> public static void Destroy() { // This is thread-safe because ThreadFlushableMemoryPool is ThreadStatic. if (ThreadFlushableMemoryPool != null) { ThreadFlushableMemoryPool.Dispose(); ThreadFlushableMemoryPool = null; } }
/// <summary> /// Creates or Flushes the FlushableMemoryPool of the current thread. /// </summary> public static void AquireOrFlush() { // This is thread-safe because ThreadFlushableMemoryPool is ThreadStatic. if (ThreadFlushableMemoryPool == null) { ThreadFlushableMemoryPool = new FlushableMemoryPool(); Logger.LogInformation("A new FlushableMemoryPool has been initialized."); } else if (ThreadFlushableMemoryPool._position > 0 || ThreadFlushableMemoryPool._memoryBlocks.Count > 1) { ThreadFlushableMemoryPool.Flush(); Logger.LogInformation($"FlushableMemoryPool '{ThreadFlushableMemoryPool.ThreadID}' has been flushed."); } }