Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Sep 19, 2025

Summary

This PR addresses community feedback on #48557 article + some cleanup

  1. Added more xrefs
  2. Inlined a couple of sub-bullets because they were not rendered nicely
  3. Added an example about RVA + AsPointer + ALC
  4. Non-zeroed fixed size buffers (see Fixed-size buffer is not zeroed runtime#119903 for more context)
  5. Reduced stackalloc size from int[512] to int[256] because previously we recommended to use 1024 bytes threshold
  6. added a new section 26. Compiler warnings

Internal previews

📄 File 🔗 Preview link
docs/standard/unsafe-code/best-practices.md docs/standard/unsafe-code/best-practices

@EgorBo
Copy link
Member Author

EgorBo commented Sep 19, 2025

@jkotas when you have a moment, could you please take a look at these changes?

@@ -947,7 +973,7 @@ While most of the suggestions in this document apply to interop scenarios as wel

## 23. Thread safety

See [Managed threading best practices](../../standard/threading/managed-threading-best-practices.md) and [.NET Memory Model](https://github.com/dotnet/runtime/blob/main/docs/design/specs/Memory-model.md).
Although memory safety and thread safety are orthogonal concepts, many of the highlighed issues in this document can lead to thread safety issues as well. For example, non-atomic coalesced writes. See [Managed threading best practices](../../standard/threading/managed-threading-best-practices.md) and [.NET Memory Model](https://github.com/dotnet/runtime/blob/main/docs/design/specs/Memory-model.md).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many of the highlighed issues in this document

What are the bullet points that this is referring to?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to

  1. Memory access coalescing
  2. Unaligned memory access

I don't have a strong opinion on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants