Skip to content

HistoryCache

Ilia Petrov-Komotskii edited this page Sep 24, 2026 · 4 revisions

HistoryCache

Fixed-length ring buffer of recent values. Not thread-safe.

using Mane.DotNet;

FloatHistoryCache fps = new(60);
fps.Append(Time.deltaTime);
float meanDt = fps.GetAverage();
fps.Clear();

API

Member Behavior
Append(value) Write; overwrite the oldest entry once full.
Clear() Reset count/index and zero the buffer.
GetAverage() Mean of stored values. Empty → type zero.

HistoryCache<T> is abstract. Concrete types:

  • FloatHistoryCache
  • DoubleHistoryCache

Unity adds Vector2HistoryCache and Vector3HistoryCache (see Random and History).

Constructor length must be greater than 0. Before the buffer fills, only the prefix of written values is valid; after it fills, the average uses every slot (order does not matter for a mean).

Clone this wiki locally