private static unsafe void TestStackAllocInts(int iterations, int length) { var len = length / 32; if (length % 32 != 0) { len++; } uint * bits = stackalloc uint[len]; for (var i = 0; i < iterations; i++) { for (var l = 0; l < length; l++) { PointerBitBuffer.Set(bits, l, !PointerBitBuffer.Get(bits, length - l - 1)); } } } public static unsafe class PointerBitBuffer { public static void Set(uint * self, int index, bool value) { var mask = 1U << (index % 32); if (value) { self[index / 32] |= mask; } else { self[index / 32] &= ~mask; } } public static bool Get(uint* self, int index) { return ((self[index / 32] >> (index % 32)) & 1) != 0; } }