Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Managed vs Unmanaged Code

Lesson 5 of 27 in the free C# Programming notes on Siksha Sarovar, written by Rohit Jangra.

The Concept of Management

In the .NET world, the term "Managed" refers to the relationship between your code and the CLR (Common Language Runtime).

Managed Code

Managed code is code that is written in a .NET language (like C# or VB.NET) and is executed by the CLR. It is called "managed" because the CLR manages its entire lifecycle.

  • Key Feature: It targets the Common Language Infrastructure (CLI), not the specific machine's CPU.

Unmanaged Code

Unmanaged code is code that is executed directly by the operating system. The programmer is responsible for everything—allocating memory, freeing memory, and security.

  • Examples: C, C++, ActiveX components, Win32 API calls.

Comparison Table

FeatureManaged Code (C#)Unmanaged Code (C++)
ExecutionRun by CLR (Virtual Machine).Run directly by CPU/OS.
MemoryGarbage Collector (GC) handles existing memory.Developer must manually allocate (malloc) and free (free) memory.
SecurityCLR enforces Code Access Security.No built-in security; vulnerable to buffer overflows.
SafetyType-safe (prevents unsafe casts).Not type-safe (allows pointer arithmetic).
PerformanceSlightly slower due to JIT compilation overhead (negligible in modern apps).Highest possible performance (Native speed).

Interoperability

.NET allows Managed code to call Unmanaged code (via wrappers like P/Invoke or COM Interop), allowing you to use legacy libraries within modern C# applications.