|
10.15.09 Pointers And Their Pitfalls By
Rodney SellersThis may seem like a very basic idea, but I have seen far too many programmers not know the proper way to handle pointers. Pointers were the first thing I learned about in my second programming class when I was in college. The teacher beat into our heads that pointers are one of the hardest things in programming to understand. The fact that you can make your own classes and functions with them is very powerful. The problem comes when you do not reallocate the memory back to the computer when you are finished with the pointer. I remember the first lesson we had on the subject, linked lists. You have a chain of elements that each has a pointer pointing to the next. Everyone in the class had trouble with losing the list because we moved a pointer when we were not supposed to. If you worded on the same machine for a long time, you would notice that it kept getting slower and slower, until it finally crashed. Our instructor told us that it was because we were taking up the computer's memory with dangling pointer. A dangling pointer is a portion of memory that is being taken up, but nothing is using it nor can the OS get it back to use for something else. The only way to get it back is to reboot the computer. He used an example of Windows 95. He said if you install Windows 95 on a computer and just let it run for 2 days it will crash. This is without installing anything onto the computer and turning the screen saver off. He said he suspects that Windows 95 has a dangling pointer problem that causes the computer to crash after 2 days. No matter what OS you are programming for, you need to watch your pointers because even on Linux, a simple dangling pointer can cause the computer to crash. If you are running this on a server for a large site, then you could fill all the computer's memory very easily. This can cause it to start using page files which would drastically slow the server or it could cause the server to crash. In conclusion, try to avoid bad code by checking your pointers and make sure the memory is released back to the OS.
|
|
| ||
|
-- CProgrammingTrends is an iEntry,
Inc. publication -- iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 2009 iEntry, Inc. All Rights Reserved Privacy Policy Legal archives | advertising info | news headlines | free newsletters | comments/feedback | submit article |