It has been quite some time I played around with Pointers and decided to go back at the one thing I like the most! But since I have been using C# since quite some time, I decided to use and implement the concept of Pointers through .NET environment.
Lots of challenges exist in the process. This is because CLR (Common Language Runtime) exists at the heart of .NET framework and it is the manager of the whole show! According to Wikipedia, ‘Managed Code’ is defined as:
‘Managed code is a differentiation coined by Microsoft to identify computer program code that requires and will only execute under the “management” of a Common Language Runtime virtual machine (resulting in Bytecode).’
For example in most OOPS languages such as C# and Java, memory allocation and garbage collection for object is controlled directly by CLR which is an example of ‘Managed Code’. But in C language, user had to allocate and free up memory by himself (alloc, malloc, calloc, realloc and free). This is ‘Unmanaged code’. There are many more examples highlighting the advantages of using the Managed Code besides making the life of a programmer easy! 😉
But, I wanted to stick to C# as the development platform and try out pointers since C# gives us the liberty to choose between Managed Code and Unmanaged/Unsafe Code. Below is a small example which highlights the basics of pointers. When running the example using Visual Studio, you would have to check the option for ‘Allow Unsafe Code’ in the Project Properties of Visual Studio.
Login