Sunday, December 26, 2010

Native Code Generator Tool-NGen


Native Code Generator Tool NGen.exe that ships with the .NET Framework can be used to compile IL code to native code when an application is installed on a user’s machine. Since the code is compiled at install time, the CLR’s JIT compiler does not have to compile the IL code at runtime, and this can improve the application’s performance. The NGen.exe tool is interesting in two scenarios:

  1. Improving an application’s startup time Running NGen.exe can improve startup time because the code will already be compiled into native code so that compilation doesn’t have to occur at runtime.
  2. Reducing an application’s working set If you believe that an assembly will be loaded into multiple processes simultaneously, running NGen.exe on that assembly can reduce the applications’ working set. The reason is because the NGen.exe tool compiles the IL to native code and saves the output in a separate file. This file can be memory-mapped into multiple-process address spaces simultaneously, allowing the code to be shared; not every process needs its own copy of the code.

Saturday, December 18, 2010

Martin Fowler in Chennai


This week, ThoughtWorks Chief Scientist, author & Agile Manifesto Co-founder Martin Fowler was in RainTree Mount hotel, Chennai on Wednesday 15 Dec. Martin shared his rich experiences & thoughts on Software Design and Architecture in the 21st Century. The talk was well organised by ThoughtWorks.

At the events, Martin shared his views on Agile methods, and in particular, Domain Specific Lanuguage (DSL) Programming; as a leading voice in these techniques, he gave a suite of short talks on his thoughts and ideas about how these methods and other developments affect software development. Itz quite interesting the way he runs the sessions. He started with interesting topic introduction as 'in stead of taking single boring topic, letz take 3 different areas'.

Itz a pleasant learning experience about documentation and itz expected level for the better productivity. Martin recommended the non traditional way of communication channel - Share and Speak. I liked his quote 'Design/develop in Group; Review individually' against the traditional vice versa path.

I feel itz a better fit for everyone in the industry like technical leads, senior project managers, architects, senior developers & testers, program managers, VPs and CXOs.

For more information on the event, visit http://www.thoughtworks.com/21st-century-software-design

Saturday, December 11, 2010

UnSafe Code


By default, Microsoft’s C# compiler produces safe code. Safe code is code that is verifiably safe. However, Microsoft’s C# compiler allows developers to write unsafe code. Unsafe code is allowed to work directly with memory addresses and can manipulate bytes at these addresses. This is a very powerful feature and is typically useful when interoperating with unmanaged code or when you want to improve the performance of a time-critical algorithm.

However, using unsafe code introduces a significant risk: unsafe code can corrupt data structures and exploit or even open up security vulnerabilities. For this reason, the C# compiler requires that all methods that contain unsafe code be marked with the unsafe keyword. In addition, the C# compiler requires you to compile the source code by using the /unsafe compiler switch.

When the JIT compiler attempts to compile an unsafe method, it checks to see if the assembly containing the method has been granted the System.Security.Permissions.Security Permission with the System.Security.Permissions.SecurityPermissionFlag’s SkipVerification flag set. If this flag is set, the JIT compiler will compile the unsafe code and allow it to execute. The CLR is trusting this code and is hoping the direct address and byte manipulations do not cause any harm. If the flag is not set, the JIT compiler throws either a System.InvalidProgramException or a System.Security.VerificationException, preventing the method from executing. In fact, the whole application will probably terminate at this point, but at least no harm can be done.

Friday, December 3, 2010

LINQ Namespace


In .NET framework history, Language INtegrated Query (LINQ) was added in CLR Version 2.0 SP1 and FW 3.5. It contains the database query integrated within the high level language like C#, VisualBasic, ASP .NET. We don't need to have a separate database access layer in the enterprise application architecture. LINQ allows you to perform type-safe queries over local and remote collections to sQL Server tables. A big advantage of LINQ is that it presents a consistent querying API across a variety of domains. The types of resolving LINQ queries reside in the below namespaces.

using System.Linq; // LINQ to In-memory Objects
using System.Xml.Linq; // LINQ to XML
using System.Data.Linq; // LINQ to SQL Server
using System.Data.Entity; // LINQ to Entity Framework
using System.Linq.Expressions // To build Expression Tree

LINQ to SQL Server and Entity Framework APIs leverage lower level ADO .NET types in System.Data namespace.