stackalloc inside a loop (CA2014)
Ce contenu n’est pas encore disponible dans votre langue.
Key dotnet.codequality.stackalloc-in-loop · Severity warning · Category codequality
Microsoft analyzer CA2014. Flags stackalloc inside a loop. Stack memory is only released when the method returns, so a long loop overflows the stack.
Incorrect
Section titled “Incorrect”for (var i = 0; i < rows; i++){ Span<byte> line = stackalloc byte[256]; Fill(line, i);}Correct
Section titled “Correct”Span<byte> line = stackalloc byte[256];for (var i = 0; i < rows; i++){ line.Clear(); Fill(line, i);}