Particularly: Is Marshal safer? Are pointers faster?
int pixel = Marshal.ReadInt32(bitmapData.Scan0, x * 4 + y * bitmapData.Stride);
int pixel = ((int*)bitmapData.Scan0)[x + y * bitmapData.Stride / 4];
There is no difference. If you look at the code from Marshal.ReadInt32
you will see it uses pointers to perform the same thing.
The only 'benefit' with Marshal
is that you not have to explicitly allow unsafe code. IIRC, you also require FullTrust to run unsafe code, so that may be a consideration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With