Ferrous API Reference

All Types / Ferrous.Testing

class AllocAssert

public static class AllocAssert

Runtime zero-allocation and allocation-budget assertions backed by GC.GetAllocatedBytesForCurrentThread. Acts as a unit-test companion to compile-time [NoAlloc] enforcement.

Methods

public static void Zero(Action action, int warmupIterations = 1)

Asserts that action allocates zero managed bytes on the current thread after running warmupIterations warmup calls.

Parameters
action
The delegate to measure.
warmupIterations
Number of warmup invocations to JIT and prime caches before measuring.
public static T Zero<T>(Func<T> func, int warmupIterations = 1)

Asserts that func allocates zero managed bytes on the current thread after running warmupIterations warmup calls, and returns its result.

Type Parameters
T
The return type of the delegate.
Parameters
func
The delegate to measure.
warmupIterations
Number of warmup invocations to JIT and prime caches before measuring.

Returns: The value returned by the measured invocation.

public static void AtMost(Action action, long maxBytes, int warmupIterations = 1)

Asserts that action allocates at most maxBytes managed bytes on the current thread after running warmupIterations warmup calls.

Parameters
action
The delegate to measure.
maxBytes
The maximum permitted allocation in bytes.
warmupIterations
Number of warmup invocations to JIT and prime caches before measuring.