I was reading on what’s new in .NET 9 and stumbled over the CrypographicOperations type which has a method called ZeroMemory
used to ensure that zeroing memory is not optimized away.
(https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-9/overview#net-libraries)
Out of curiosity I went to look into the code which just calls Clear()
on the span and contains two comments:
// NoOptimize to prevent the optimizer from deciding this call is unnecessary
// NoInlining to prevent the inliner from forgetting that the method was no-optimize
(Link to GitHub Code)
Why/how can the inliner “forget” the anti-optimization hint?
1