Skip to content

Unsafe.As vs Unsafe.BitCast #104626

Discussion options

You must be logged in to vote

Unsafe.BitCast works on value types and doesn't require taking an address, which can improve the overall codegen/perf in some complex scenarios (in simple ones the JIT will normally recognize its not actually "address-taken").

It also helps guarantee correctness as it also requires the input/output be the same size and therefore that you aren't accessing bits that don't exist.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by colejohnson66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants