tags:

views:

203

answers:

1

Anybody have any idea why the BCL team chose to use Byte* instead of IntPtr in the constructors for UnmanagedMemoryStream? This forces you into using an unsafe context in order to construct the type. It seems like they could have used IntPtr and that wouldn't have forced the unsafe context.

+2  A: 

I'd guess because it is safer. If they would have used IntPtr, the constructor could be called with any garbage value. With byte* there's at least a shot at the compiler verifying that the memory is valid and pinned. Albeit that casting an IntPtr to byte* is pretty simple.

Hans Passant