What on Earth is a Pointer?
In the world of software development a pointer is a data type that stores a value that “points” to another value stored in memory. The actual value of the pointer type is the memory address of the value to which it points. The purpose of a pointer is to reference data stored in memory. This is particularly useful when designing data structures, such as linked lists, and passing data to functions within an application. Pointers serve as a reference to another data variable when used to pass data to functions. Among other things, this technique provides a mechanism for function to manipulate and “return” multiple values.
The most common example of pointer use is in passing values to functions by reference, which I mentioned above. Consider the following:
(Example shown in the C++ language)
int ChangeThem(int value1, int *value2)
{
*value2 += 5;
return value1 += 10;
}
int main()
{
int val1 = 0, val2 = 0;
val1 = ChangeThem(val1, &val2);
cout << “Value 1 is “ << val1 << “ and value 2 is“ << val2 << “.” << endl;
return 0;
}
Output: Value 1 is 10 and value 2 is 5.
Notice that the value of the val2 variable was changed despite the fact that it was not explicitly returned from the function. This is because the memory address of val2 was passed to the function ChangeThem, not the actual variable. The function could directly manipulate the data stored at the passed memory address, which allowed the function to modify non-global variables outside of their scope.
Obviously pointers are a very convenient feature of programming languages. They should always be used with care as they are quite easy to abuse. Used properly, however, pointers open the door to a lot of programming power.
What are the Drawbacks to Using Pointers?
Pointers are a very powerful feature of several programming languages. They open the door to powerful and complex techniques that would not be otherwise possible without pointers. However, as the old say goes, “with great power comes great responsibility.” This is very true of pointers. Pointers may be powerful, but they are also potentially hazardous to the health of the software applications in which they are used.
Improper pointer use is often the chief bug in software applications. Security is a huge concern when using pointers. Since pointers are treated as numbers within a program, they can be made to point to anything – even data that isn’t part of the running program. Additionally, pointers allow functions to manipulate data outside of its scope, thus circumventing any pre-designed security models (such as private or hidden members).
Another possible problem with pointers is that they make it quite easy for programmers to reference memory areas that no longer contain expected data. For example, a programmer might allocate memory for some purpose, then point to that memory with a pointer variable, and later deallocate that memory without removing the pointer. Later use of said pointer would, at best, produce unexpected result, and at worse – system instability or failure. Another example is when a programmer declares a pointer but does not initialize it to point at any specific address. These types of pointers are known as wild pointers, and they can point to literally anywhere in memory. Obviously, inadvertently using wild pointers is likely to produce unexpected results.
Pointers are powerful, but they are also potentially dangerous. If programmers take care, however, they can avoid most of the pitfalls surrounding pointer use. This, of course, is a good thing since pointers are often absolutely necessary components of software applications.
How UltiMesh Addresses the Issue
With all the potential for pointer misuse, UltiMesh implemented strict policy regarding their use. First, we design and build nearly all of our software to run on top of the powerful Microsoft .Net Framework. Additionally, we use the C# programming language heavily when implementing our solutions. Both C# and the .Net Framework address the security and stability issues of pointers.
The C# Language allows pointers, but limits the potential for negative impact. C# only allows pointers to point to value types and arrays - reference types cannot be pointed to in C#. Additionally, C# requires that pointers are handled differently than other managed code. Code blocks that use pointers must be flagged as unsafe to notify the compiler and the runtime of the potential for instability. The specifics regarding pointers are aptly covered in this excellent article by Rajesh V.S.
In addition to using inherently safe and secure platforms, languages and technologies, UltiMesh also has a policy regarding when pointers can be used. In short, UltiMesh developers are not allowed to use pointers unless there are quantifiable performance benefits or if some solution cannot be solved any other way. In other words, we don't take risks with our clients. The end result is that your UltiMesh products are high performance, rock solid and secure.
So... regardless of the risks surrounding pointers - UltiMesh has you covered. Take a look at how we can help you!