articles

Home / DeveloperSection / Articles / Deep C# - What's The Matter With Pointers?

Deep C# - What's The Matter With Pointers?

Deep C# - What's The Matter With Pointers?

Dick Grey912 22-Nov-2019

In a modern language the argument is that you should never need to get down and dirty with pointers because to do so simply reveals that you are thinking at too primitive a level and in severe danger of meeting the real hardware that underpins everything. 

While this is true there are still times when reality pokes through the abstraction and you do have to interact with the hardware in ways that can only be achieved using pointers. In addition there are all those wonderful C and C++ programs that use pointers and need to be converted to something more polished and safe.

In short, you certainly should know about pointers even if hopefully you never actually make use of them in a real production application. If you do find that pointers are essential to something low level that you are trying to implement then it is also important that you know how to implement them in as “safe” a way as possible.

This simple idea has become increasingly complicated as hardware has developed and with the introduction of hardware memory mapping. Now the address that data is stored at can change without the data being moved due to the use of address translation hardware. Even if the hardware doesn’t get in the way, addresses change while an application is running because the operating system or a garbage collection system often moves things around to make things more efficient.

The point is that while once the address of something was a fixed and reliable way of accessing it, today it is surrounded by a range of problems.

The “pointer” is the step in abstracting the idea of an address. At its most basic a pointer is simply a variable that can be used to store the address of something. You can use a pointer to gain access to the data item pointed at – a process called dereferencing. You can also subject the pointer to arithmetic operations that move its location in the “store”.


I am 26-year-old health centre receptionist who enjoys extreme ironing, hockey and binge-watching boxed sets. I am friendly and reliable, but can also be very lazy and a bit moody.

Leave Comment

Comments

Liked By