This is not what unsafe
and *
is for. Seriously: do not do this. What you are doing here is essentially references. For that: use a class
, not a struct
. This is going to hurt you very very very badly otherwise.
Also: this is not what struct
is for. Looking at a mutable struct
like this tells me in an instant that you aren't appreciating what struct
is intended to do.
If you want to know where nonsense values are coming from: the pointers aren't to pinned locations. The fix to this is not "oh, so I need to pin them". It is "use references, not pointers".