<PackageReference Include="Microsoft.ApplicationInsights" Version="2.23.0" />

Microsoft.ApplicationInsights.Metrics.Extensibility.MetricValuesBufferBase<TValue>

abstract class MetricValuesBufferBase<TValue>
The metric values buffer is the the heart of the lock-free (well, mostly) aggregation logic. If allows to quickly collect metric values and to update the running aggregate at regular intervals. This is required becasue aggregates for some aggregation kinds are expensive to update (e.g. some percentile algorithms) and/or require a lock. By collecting a bunch of values first, the expensive/locked operation can occur less frequently.
public int Capacity { get; }

public int NextFlushIndex { get; set; }

public MetricValuesBufferBase(int capacity)

public TValue GetAndResetValue(int index)

protected abstract TValue GetAndResetValueOnce(TValue[] values, int index)

public int IncWriteIndex()

protected abstract bool IsInvalidValue(TValue value)

public int PeekLastWriteIndex()

public void ResetIndices()

public void ResetIndicesAndData()

protected abstract void ResetValues(TValue[] values)

public void WriteValue(int index, TValue value)

protected abstract void WriteValueOnce(TValue[] values, int index, TValue value)