Search notes:

.NET: Managed code

Managed code runs in and using the Common Language Runtime (CLR).
The CLR loads the (platform indipendent) MSIL that was produced by a .NET compiler and, as a second compilation step, turns it into (platform dependent) native code. (This second step is referred to Just in Time (JIT) compilation).
An important property of managed code is that is contains the information about the types the code uses which makes refelection possible (namespace System.Reflection).

Memory Management

In managed code, memory management is taken care for by the garbage collector.

Strings

In managed code, strings are always encoded in UTF-16.

Verification process

In order to run managed code, it must undergo a verification process. (It is possible, however, for the administrator to grant a permission to skip this process).
This verification process checks if the code being verified does not try to access invalid memory addresses or perform other potentially dangerous actions.
If the managed code passes the verification, it is said to be type-safe.
Tha advantage of type-safe code is that the Common Language Runtime is able to provide better isolation by not sacrificing performance.

Interaction with unmanaged code/memory

System.Runtime.InteropServices.GCHandle provides a way to access managed objects from unmanaged memory.
The System.Runtime.InteropServices.Marshal class allows to interact with unmanaged memory and convert between unmanaged and managed memory.

Passing strings from managed to unmanaged code

In order to pass strings from managed code to unmanaged code. System.Runtime.InteropServices.MarshalAsAttribute is required because managed strings are stored differently in memory than unmanaged string.
With the System.Runtime.InteropServices.MarshalAsAttribute instruction, the necessary conversion will be performed.

See also

In order to debug managed code, SOS.dll and mscordacwks.dll is needed.

Index