ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalEC-332Dotnet Framework Manag…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    EC-332

    Enterprise Application Development

    Progress0 / 37 done
    Topics37
    1Microsoft technology history2Introduction to .NET and its architecture3Concept of MSIL, CLR, CLS, CTS
    4Managed and Unmanaged Code5.Net Assembly6Introduction to C# fundamentals7Boxing and Unboxing8Implementing multi-tier architecture
    9SQL Injection, parameterized queries10Usage of data set, Data adapter and command builder in disconnected model
    11Multicast delegates12Introduction to windows forms13HTML
    14javascript and its data types, variables, functions15Debugging javascript using Firebug
    16Browser's Object (BOM), Document Object Model
    17Jquery effects
    18LINQ to Objects, LINQ to SQL19Query syntax, Operations (projection, filtering and join) using Linq Queries
    20The entity data model, CSDL21Eager vs lazy loading, POCO classes, DBContext API22Querying entity data models23Introduction to ASP.NET MVC24MVC application structure, Controllers overview25Action Methods, Parameterized action methods26Introduction to razor syntax27Code expressions, Code Blocks, Implicit Vs Explicit Code Expression28Data annotations, Client and Server Side Validation29Validation and model binding, Validation and model state30MVC Membership, Authorization and security
    31SOAP, WSDL32Service contract, Data contract, XML, WCF bindings33ABC of WCF, Restful services34Consuming rest services (CRUD operations) using Jquery AJAX and JSON35Introduction to web API36Example of web API using CRUD Example37MVC routing
    6 min read
    Topic 4 of 37
    Topic Study Note Illustration
    04

    Introduction to .NET framework: Managed and Unmanaged Code

    The .NET Framework is a comprehensive development platform provided by Microsoft for building and running applications. It includes a large class library, known as the Base Class...

    The .NET Framework is a comprehensive development platform provided by Microsoft for building and running applications. It includes a large class library, known as the Base Class Library (BCL), and the Common Language Runtime (CLR), which manages the execution of programs written in different languages like C#, VB.NET, and F#. One of the important distinctions in the .NET Framework is the concept of managed and unmanaged code.

    Managed Code

    Managed code is the code that runs under the control of the Common Language Runtime (CLR) in the .NET Framework. The CLR provides several services to managed code, such as memory management, security, and exception handling, ensuring that code execution is safe and efficient.

    Key Features of Managed Code:

    1. Automatic Memory Management (Garbage Collection):

      • One of the most important aspects of managed code is automatic memory management. The CLR's garbage collector (GC) automatically reclaims memory that is no longer being used by the program, freeing developers from manually managing memory allocation and deallocation.
    2. Type Safety:

      • Managed code is type-safe, meaning that the compiler ensures that objects are used according to their data type. This helps prevent type-related errors during runtime, which are common in unmanaged environments.
    3. Security:

      • The CLR performs code verification to ensure that the code adheres to certain safety rules, preventing issues like buffer overflows or unauthorized access to memory. This is part of code access security (CAS), which helps enforce restrictions on what code can or cannot do.
    4. Exception Handling:

      • Managed code supports structured exception handling (e.g., try/catch blocks). The CLR manages exceptions in a way that makes the program more robust and easier to debug.
    5. Cross-Language Interoperability:

      • Managed code allows for interoperability between different .NET languages (like C#, VB.NET, and F#). The CLR enables these languages to interact with each other, using a common type system (CTS) and runtime environment.
    6. JIT Compilation:

      • Managed code is first compiled into Microsoft Intermediate Language (MSIL) and stored in assemblies. When the program is executed, the CLR uses the Just-In-Time (JIT) compiler to convert the MSIL code into machine code that the computer’s processor can execute.

    Unmanaged Code

    Unmanaged code, on the other hand, refers to code that runs directly on the operating system without the supervision of the CLR. Unmanaged code is typically written in languages like C or C++ that allow direct interaction with hardware and memory.

    Key Features of Unmanaged Code:

    1. Manual Memory Management:

      • In unmanaged code, developers are responsible for allocating and freeing memory explicitly. This gives them greater control but also introduces the risk of memory leaks and errors, such as dangling pointers (pointers pointing to invalid memory) or buffer overflows.
    2. Performance:

      • Since unmanaged code bypasses the overhead of the CLR, it often has better performance and can execute faster, especially in cases where low-level operations (like hardware interaction or performance-critical calculations) are needed.
    3. No Safety Checks:

      • Unmanaged code lacks the type safety and security features that managed code benefits from. This can lead to unsafe memory access, leading to crashes, security vulnerabilities, or even system instability.
    4. No Garbage Collection:

      • Unmanaged code doesn’t benefit from automatic memory management. The developer must handle memory allocation, deallocation, and cleanup manually, which can be error-prone.
    5. Platform-Specific:

      • Unmanaged code is often platform-specific, meaning that the code needs to be compiled and optimized for each target operating system or architecture. This makes it less portable compared to managed code.

    Key Differences Between Managed and Unmanaged Code

    Feature Managed Code Unmanaged Code
    Memory Management Automatic (Garbage Collection) Manual (developer manages memory)
    Type Safety Ensured by the CLR (Type-Safe) Not enforced, can be unsafe
    Security Managed by CLR (Code Access Security) No inherent security
    Exception Handling Supports structured exception handling Typically doesn’t have built-in handling
    Performance Slightly slower due to CLR overhead Faster (no CLR overhead)
    Interoperability Cross-language interoperability via CLR Not easily interoperable
    Portability Runs on any platform with CLR support Platform-specific (OS-dependent)

    When to Use Managed vs. Unmanaged Code

    • Managed Code is ideal for most applications, especially those where ease of development, security, memory management, and cross-language interoperability are important. Common examples include web applications, desktop software, and mobile applications built with .NET technologies like C# and ASP.NET.

    • Unmanaged Code is typically used when you need to write performance-critical code or interact with hardware or system-level resources. For example, system-level programming, graphics rendering, or working with device drivers is often done in unmanaged code (like in C/C++).

    How .NET Works with Unmanaged Code

    .NET allows you to work with unmanaged code through Platform Invocation Services (P/Invoke) and COM Interop:

    1. P/Invoke (Platform Invocation Services):

      • P/Invoke allows you to call unmanaged functions (like those in Windows API or DLLs) from managed code. You use P/Invoke when you need to call an unmanaged library or interact with a system API that is not part of the .NET Framework.
    2. COM Interop:

      • COM Interop allows .NET applications to interact with Component Object Model (COM) components, which are often unmanaged. This is useful for integrating legacy unmanaged code with .NET applications.
    3. Unsafe Code:

      • In some cases, you might write unsafe code in managed code (using unsafe keyword in C#). This allows direct memory manipulation and pointer arithmetic, making the code behave more like unmanaged code.

    Conclusion

    The .NET Framework makes a clear distinction between managed and unmanaged code. Managed code is safer, easier to develop, and offers better memory management, security, and cross-language interoperability through the CLR. Unmanaged code, however, provides better performance and direct access to system resources but lacks the safety and features provided by the CLR. Depending on the requirements of your application, you might use one or both of these types of code to meet your needs.

    ← Previous topic 3
    Concept of MSIL, CLR, CLS, CTS
    Next topic 5 →
    .Net Assembly

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    6mremaining
    942words
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Enterprise Application Development