ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Enterprise Application Development
    EC-332
    Progress0 / 37 topics
    Topics
    1. Overview of Enterprise Application Development: Microsoft technology history2. Introduction to .NET and its architecture3. Concept of MSIL, CLR, CLS, CTS4. Introduction to .NET framework: Managed and Unmanaged Code5. .Net Assembly6. Introduction to C# fundamentals7. Boxing and Unboxing8. Implementing multi-tier architecture9. Introduction to ADO.Net: SQL Injection, parameterized queries10. Usage of data set, Data adapter and command builder in disconnected model11. Introduction to delegate: Multicast delegates12. Introduction to windows forms13. HTML14. Introduction to javascript: javascript and its data types, variables, functions15. Debugging javascript using Firebug16. Introduction to various object models: Browser's Object (BOM), Document Object Model17. Introduction to Jquery: Jquery effects18. Introducing LINQ: LINQ to Objects, LINQ to SQL19. Query syntax, Operations (projection, filtering and join) using Linq Queries20. Introduction to ADO.NET entity framework: The entity data model, CSDL21. Eager vs lazy loading, POCO classes, DBContext API22. Querying entity data models23. Introduction to ASP.NET MVC24. MVC application structure, Controllers overview25. Action Methods, Parameterized action methods26. Introduction to razor syntax27. Code expressions, Code Blocks, Implicit Vs Explicit Code Expression28. Data annotations, Client and Server Side Validation29. Validation and model binding, Validation and model state30. MVC Membership, Authorization and security31. Introduction to service-oriented architecture: SOAP, WSDL32. Service contract, Data contract, XML, WCF bindings33. ABC of WCF, Restful services34. Consuming rest services (CRUD operations) using Jquery AJAX and JSON35. Introduction to web API36. Example of web API using CRUD Example37. MVC routing
    EC-332›Introduction to .NET framework: Managed and Unmanaged Code
    Enterprise Application DevelopmentTopic 4 of 37

    Introduction to .NET framework: Managed and Unmanaged Code

    6 minread
    942words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time6 min
      Word count942
      Code examples0
      DifficultyIntermediate