是什么在C#不安全代码和非托管代码之间的区别?

问题描述:

什么是用C#不安全的代码和非托管代码之间的区别?

What is difference between unsafe code and unmanaged code in C#?

托管代码下的CLR的监督运行(通用语言运行时)。这是负责的事务,如内存管理和垃圾收集。

managed code runs under supervision of the CLR (Common Language Runtime). This is responsible for things like memory management and garbage collection.

所以非托管只需运行CLR的上下文之外。不安全的是那种之间托管和非托管。不安全仍然在CLR下运行,但它会让你直接通过指针访问内存。

So unmanaged simply runs outside of the context of the CLR. unsafe is kind of "in between" managed and unmanaged. unsafe still runs under the CLR, but it will let you access memory directly through pointers.