Avoiding the cost of "fixed" when a struct is known to be situated in unmanaged memory. #8011
Replies: 3 comments 11 replies
-
Isn't that already |
Beta Was this translation helpful? Give feedback.
-
Also, unsafe code cannot appear inside iterators, if this is related to the possibility of the GC messing up the iterators state, then could this too be changed so that if the unsafe code is only accessing a Eric Lipper explains that (apart from it being in bad taste) it is because of the GC and the need to perhaps pin something for the duration of the enumeration, so again if the unsafe code is only accessing a Imagine a scenario where we need to walk raw memory, perhaps an unmanaged linked list or something, this is a use case. |
Beta Was this translation helpful? Give feedback.
-
If we have a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Methods in structs that need to get their own address (
&this
) currently can only do so within afixed
statement. This could be avoided if thestruct
were somehow annotated in such a way that it could never be situated in the managed heap.Perhaps
unmanaged
orfixed
or something, could be added as an option when declaring astruct
. Any attempt to declare a field of this type inside aclass
(or nested inside other structs inside a class) would fail. Because thestruct
can be guaranteed to never be situated in the managed heap, it will be safe to allow methods and properties in these structs to avoid the overhead of usingfixed
when getting their own address.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions