Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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

like image 280
ashish Avatar asked Sep 22 '10 15:09

ashish


People also ask

What is differences between managed code and unmanaged code?

Managed code is the one that is executed by the CLR of the . NET framework while unmanaged or unsafe code is executed by the operating system. The managed code provides security to the code while undamaged code creates security threats.

What is unsafe code in C?

What Does Unsafe Mean? Unsafe is a C programming language (C#) keyword used to denote a section of code that is not managed by the Common Language Runtime (CLR) of the . NET Framework, or unmanaged code. Unsafe is used in the declaration of a type or member or to specify block code.

What is managed code and unmanaged code with example?

It gets the managed code and compiles it into machine code. After that, the code is executed. The runtime here i.e. CLR provides automatic memory management, type safety, etc. C/C++ code, called "unmanaged code” do not have that privilege.

What is an unmanaged code?

Code that executes under the control of the runtime is called managed code. Conversely, code that runs outside the runtime is called unmanaged code. COM components, ActiveX interfaces, and Windows API functions are examples of unmanaged code.


1 Answers

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

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.

like image 97
NullUserException Avatar answered Oct 21 '22 15:10

NullUserException