Managed Code
Managed Code is code that is written to target the services of the
managed runtime execution environment (CLR). The Managed Code is always
executed by managed Code runtime environment rather than OS directly. It
refers to a method of exchanging information between the program and
the runtime enviornment. The environment also provide the necessary
security checks before executing piece of code. Managed code also get
different services from the untime environment like
Garbage collection
Type Safety
Exception handling.
Bounds Checking
Therefore managed code does not have to worry about memory
allocations, type safety. Applications written in java, c#, VB.net, etc
target a runtime environment which manages the execution and the code
written using these languages is known as managed code. Managed Code is
always compiled into a intermediate languages (MSIL in Dot net).
These compiler used by .net framework to compile managed code
compiles it into an intermediate language and generate necessary
metadata and information.
In .Net framework managed code runs with in the .net framework’s CLR
and get all services provided by CLR. After compile managed code an
executable is created. When user run the executable the Just in time
compiler of CLR compiles IL into native code specific to architecture of
machine or machine code.
Managed Code also provides platform independence. As the managed
code is first compiled to IL, the CLR’s JIT compiler takes care of
compiling this IL into architecture specific instructions.
Unmanaged Code
Code that is directly executed by the operating System is known as
an un-managed code. Applications written in VB 6.0, C++, C etc are all
examples of unmanaged code. Unmanaged code typically targets the
processors architecture and is always dependent on the computer
architecture. If you want to run the same code on different architecture
then you have to recompile the code using that particular architecture.
Unmanaged code is always compiled to the native code. Unmanaged code
does not get any services from the managed execution environment.
In unmanaged code the memory allocation, type safety, security needs
to be taken care of by the developer. This makes unmanaged code prone
to memory leaks like buffer over burns and pointer overrides etc.
Difference between Managed Code and Unmanaged Code
Code that targets the common language runtime is known as managed
code. But unmanaged code is executed directly by operating System.
Managed Code is executed under the instruction of CLR. But unmanaged
cannot executed under the instruction of CLR.
The code is understandable by CLR in case of managed. But in case of
unmanaged code is not understand by CLR.
In managed code compilation process is done is two phase- Code to
MSIL and then MSIL to machine language. But in case of unmanaged code,
the code compilation is done in one phase, code to machine code.
Languages used in writing managed code are, Java, C#, VB.net, etc
which uses runtime environment. But languages used in writing unmanaged
code are vb 6.0, C++, C etc.
Managed code provides Garbage Collection or Automatic memory
allocation and de-allocation. But unmanaged code does not provide memory
allocation features.
Managed code also provides platform independence. But unmanaged code
is platform dependence.
In case of managed code is compiled into MSIL (Microsoft
intermediate Language). In case of unmanaged code, code is compiled into
machine language.
Managed Code provides Type Safety. But unmanaged does not provide
Type Safety.
Unmanaged code is more error prone then managed code.
In unmanaged code the memory allocation or other services needs to
be taken care of by the developer. But developer is no need to take care
of these services in managed code.
Key Features available to managed code applications includes.
Performance gained from executing all code in the CLR. Calling
unmanaged code decrease performances because addition security check are
required.
Ease of deployment and vast improved versioning facilities the end
of “DLL Hell”.
Built-in Security by using code access security and avoiding buffer
overruns.
It provides scalability features.
Provide improvement to application stability.
Provide cross-language integration.
This permits applications built with managed code to perform more
safety and efficiently.
分享到:
相关推荐
ASP.NET中的托管代码和非托管代码是两种不同的代码执行方式,它们在.NET框架中扮演着重要的角色。了解这两种代码类型对于开发高效、安全且可维护的.NET应用至关重要。 托管代码,顾名思义,是由.NET运行时环境(也...
相反,非托管代码则是指不依赖于.NET Framework执行的代码,如C++原生代码或者DLL,它们不享受CLR提供的服务,但可能拥有更高的性能和更直接的系统访问权限。 书中的重点之一是阐述托管代码与非托管代码之间的交互...
.NET Framework的代码被称为托管代码,因为它是在Common Language Runtime(CLR)的管理下运行。CLR负责内存管理、安全性、跨语言交互等功能。其中,内存管理的一个重要特性是垃圾回收,它自动清理不再使用的内存,...
基本上是 .NET Framework 2.0 的 Microsoft 实现,当然是实际发布的 .NET Framework 2.0 的一个简化版本。 sscli 2.0 中包含很多有趣的东西,包括: 01、vm - 包含了 CLI 核心实现,包括垃圾收集器、类装入器、...
托管代码是指使用 .NET Framework 编译的代码,而非托管代码是指使用其他语言编译的代码,如 C++、C 等。托管代码和非托管代码之间的交互是通过 CLR 实现的,CLR 负责将托管代码和非托管代码之间的数据交换。 封送...
同时,它支持更多语言,如Visual Basic .NET、C#、C++托管代码等,增强了多语言的互操作性。 2. LINQ(Language Integrated Query)的前身:虽然LINQ在.NET Framework 3.5中正式引入,但其基础概念在2.0版本中已经...
托管代码是在.NET框架下编译的高级语言代码(如C#、VB.NET或F#等)。这些语言编译后的中间语言(Intermediate Language, IL)被加载到CLR,由CLR进行Just-In-Time (JIT)编译成机器码执行。这种机制使得.NET代码能够...
标题中的“(64位操作系统Framework4.7.2)C:\Windows\Microsoft.NET下的Framework”指的是在64位操作系统的环境下,安装了.NET Framework 4.7.2的特定目录。.NET Framework是微软开发的一个运行库,它为开发者提供...
首先,.NET Framework 2.0是微软推出的一个全面的开发平台,它提供了一个一致的面向对象的编程环境,无论是本地代码还是托管代码,都可以在Windows操作系统上运行。2.0版本在1.1的基础上进行了大量改进和增强,包括...
- .NET Framework通过Platform Invoke (P/Invoke)和Component Object Model (COM) Interop,允许.NET代码调用非.NET(例如,C/C++ DLLs或COM组件)的代码。 15. **ADO.NET** - ADO.NET是.NET Framework中用于...
P/Invoke是.NET Framework提供的一种机制,允许C#代码调用Windows API或其他非托管DLL中的函数。通过定义`extern`关键字的函数,并使用`DllImport`属性来指定DLL的路径和函数名,可以实现C#与非托管代码的交互。...
.NET Framework则是微软的软件框架,它为开发者提供了一个运行环境,使得开发者可以创建跨平台的、基于托管代码的应用程序。.NET Framework包含了Common Language Runtime(CLR),这是一个执行环境,负责内存管理、...
托管与非托管代码是编程领域中的两个重要概念,主要涉及.NET框架和C++等语言的使用。这篇文章将深入探讨这两者的差异,以及它们在实际开发中的应用。 托管代码(Managed Code)是指能够在.NET Framework的公共语言...
.NET Framework 数据提供程序描述用于在托管空间中访问数据源(如数据库)的类的集合。 System.Data.Linq 包含支持在 LINQ to SQL 应用程序中与关系数据库进行交互的类。 System.Data.Linq.Mapping 包含用于生成...
1. 托管DLL:由.NET Framework管理的代码,遵循.NET的语法规则,编译后生成MSIL(中间语言),在运行时通过JIT(Just-In-Time)编译器转化为机器码执行。托管DLL具有垃圾回收、类型安全和跨语言交互等特性。 2. 非...
基于C#的.NET Framework程序设计。 第1章 Microsoft .NET Framework概述 第2章 托管执行环境的介绍 ...第15章 托管代码与非托管代码之间的互操作 第16章 使用Microsoft ADO.NET 访问数据 第17章 属性
8. **互操作性**:提升了与COM组件、WinRT(Windows Runtime)和非托管代码的互操作性。 9. **安全性和稳定性**:修复了许多已知的安全漏洞,增强了框架的整体稳定性和安全性。 10. **部署和配置**:改进了安装和...
.NET Compact Framework 将托管代码和 Web 服务带给了智能设备,它允许安全的、可下载的应用程序在诸如个人数字助理 (PDA)、移动电话和机顶盒等设备上运行。 .NET Compact Framework 的主要特点包括: 1. 可以在...
.NET Framework 2.0强化了不同编程语言之间的互操作性,通过Common Intermediate Language (CIL) 和 Common Type System (CTS),使得VB.NET、C#、C++/CLI等语言可以无缝协作,共享代码资源,进一步降低了多语言项目...
Common Language Runtime(通用语言运行时)是.NET Framework的核心组件之一,负责执行托管代码。它提供了一系列服务,包括内存管理、线程管理和安全性控制等,以确保应用程序的稳定性和安全性。CLR还引入了Just-In-...