Satview: Pointer Perfect, Part 3
(Page 1 of 6 )
Smart pointers allow you to manage the memory in a program yourself, without relying on garbage collectors. If you're building performance critical software, you need to know how to use pointers. In this third article in our series covering how to use pointers, J. Nakamura takes a look at what smart pointers can do, and warns about the pitfalls to avoid.
In the previous articles we looked at methods we can use to employ pointers in C++. If pointers are that useful, then why do most modern languages make such a big deal of not using them and come with garbage collectors instead? The answer is quite simple: you need to travel quite a steep learning curve to become a responsible pointer user and it is much easier to rely on a garbage collector to look after your memory usage.
I don’t want to start a holy language war here, but I do want to point out that when you are building performance critical software, you want to be managing the memory yourself. Even when you are not working on high performance software, you should still be aware of memory usage and the kind of tasks from which a garbage collector relieves you! There is no excuse to go on a memory abuse rampage. Computer programming is a complex task and even though the learning curve can be flattened out by using garbage collectors, it doesn’t necessarily mean that the task itself has become less complex. It all depends on what you want the machine to do for you.
Let’s take a closer look first at why the usage of pointers can be dangerous, then I will introduce some mechanics C++ enables you to create, in order to make it safer to rely on pointers. Originally I expected that this topic would fit in one article, but there is so much to say about smart pointers that I have to spread it out over several articles instead. In this article we will mainly be looking at the STL std::auto_ptr.
Next: Functions >>
More C# Articles
More By J. Nakamura