I looked at the Interlocked.Or method in .NET 5. This is great for two integer values. Is there a way to perform the equivalent of this on two separate byte values?
I searched the documentation, and I can see that InterlockedOr8 exists in winnt.h
, but P/Invoking it would not produce good performance characteristics.
I have tried calling Interlocked.CompareExchange<T>
as follows, just to see if I could simply call it in general with some byte values:
var map = new byte[268435456];
Interlocked.CompareExchange(ref map[0], (byte)137, (byte)137);
But I get the following error:
Error CS0452 The type 'byte' must be a reference type in order to use it as parameter 'T' in the generic type or method 'Interlocked.CompareExchange(ref T, T, T)'