DEV Community

Pablo Miranda
Pablo Miranda

Posted on

Managed code

Manage coded as I wrote before comes with a cost because the safety net that brings have multiple layers of complexity.

Benefits

Managed code over unmanaged code indeed has a plus side.

Type Safety

Enforced by the compiler and runtime, so objects are used as they are plus boundaries, overflow detection, here what's really important is that the heap can not be corrupted due invalid pointers or memory access violations.

Memory is managed, with some advanced language features found on a higher level of abstraction. Reflection certainly provides a dynamic component managing extensions.

Drawbacks

  • There is no access to the full processor instruction set.
  • New windows features come first to C/C++ windows sdk and some functionality still don't have any managed wrapper.
  • There is no direct memory access plus no control over the memory layout of structures.

Performance

This high-level managed code is translated to Intermediate Language, then when the code is run the CLR invokes the JIT compiler to convert your IL to assembly code where most important code optimizations happen and also performance suffers this one time hit and from then you always get the compiled version.

The quality of the generated code is not on our hands which gets better on each .NET framework release. Memory management does have some points in favor with a properly configured garbage collector, since it compacts the heap memory fragmentation is less of an issue.

Another issue is that memory allocations are trivial and generic API features come with expensive implementations in favor of make them universal and here is the why and where we want to understand better the software we write as developers.

Top comments (0)