C Programming Tutorials and advice
CProgrammingTrends News Archives About Us Feedback


Click to Play

Is Your Site Secure?
The Internet is an amazing place, but it can also be very dangerous. Many times, webmasters are so focused on issues such as duplicate content that they neglect...

Recent Articles

Worldwide Programming Competition To Begin Soon
Keep an eye out - or get your application in - if you're interested in a competition that should unearth and crown some of the world's best programmers. The IEEEXtreme Programming Competition 3.0 will take place...

CodePlex Foundation, MySpace's Qizmt
MySpace announced that they're open sourcing Qizmt, a MapReduce framework used by the MySpace Data Mining team. Unlike other leading MapReduce frameworks...

August TIOBE Index Indicates Growth
The C, C++, and C# programming languages all performed well in the latest TIOBE Programming Community Index. One of them held its ground in terms of overall rankings, while the other two managed...

Garbage Collection And C
Garbage collection is an extremely undervalued aspect of modern society. After all, we couldn't be buzzing around in hybrids and enjoying our plasma TVs if we were...

10.15.09

Pointers And Their Pitfalls


By Rodney Sellers

This 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.

About the Author:
Rodney Is A Staff Writter for iEntry.
About CProgrammingTrends
A collection of articles and tutorials designed to help C and C variant programmers in their programming work. C Programming Tutorials and advice





CProgrammingTrends is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagmentNews.com





-- 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


CProgrammingTrends Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact