3 ms·
Unsafe code( pointers ), shows and example of a copy, where a byte* is casted to a int* and then dereferenced. Such operation in c produces undefined behavior(
by deletes 13y ago
Unsafe code( pointers ), shows and example of a copy, where a byte* is casted to a int* and then dereferenced. Such operation in c produces undefined behavior( even if byte points to data large enough ).
Safe or not, does c# consider such dereference as defined behavior?
- VexXtreme 13y agoThere is no concept of "dereferencing" in C# because there are no pointers. Technically it is possible to force the environment to allow you to write unsafe code but I've never seen this in reality and I'm having a hard imagining where it would be useful.
- ygra 13y agoOne thing where it is useful is manipulating image data. You can get a raw pointer from the Bitmap class you can then manipulate with unsafe code which is orders of magnitude faster than the normal variant. Basically you're saying, for a single method or a block of code "Please turn off all safety nets, but only for these 20 lines". The places where it's useful or necessary are quite few, though.
- deletes 13y agoThe tutorial ( story link ) says otherwise: http://msdn.microsoft.com/en-us/library/aa288474%28v=vs.71%29.aspx http://msdn.microsoft.com/en-us/library/aa288474%28v=vs.71%2...
- taspeotis 13y ago> There is no concept of "dereferencing" in C# because there are no pointers. You seem to have confused C# with some totally different language [1]. [1] http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx