Allow fixed ref
function parameters
#8951
Replies: 2 comments 5 replies
-
This is not how modern C# using buffers. Instead, |
Beta Was this translation helpful? Give feedback.
-
FixedRef is rather an annotation/type concept - simply an indicator that this value can be safely converted to a pointer and used in a non gc-aware place. You can define your own ref struct that represents this concept. I dont think language change is warranted here. With upcoming roles/shapes/extensions/whatever I believe you can even use an "alias" instead of a real struct. |
Beta Was this translation helpful? Give feedback.
-
Currently structs passed by value have a fixed location within the scope of the function, and their address can be taken without using a fixed statement as shown in
F1
below.The address may also be passed to other functions and dereferenced without using an additional fixed statement, as shown in
F2
below.However, if the struct is passed by
ref
to another function, an additional fixed statement is needed in order to avoid a compiler error, as shown inF3
andF4
below.I would like to propose
fixed ref
parameters, which allow passing by ref from an already fixed location without an additional fixed statement. Attempting to pass from an unfixed location would result in a compiler error.I believe that passing by
fixed ref
is superior to passing by pointer because it preserves the syntax of pass by value, similar to how passing byconst&
in C++ is generally preferred to passing by pointer.Beta Was this translation helpful? Give feedback.
All reactions