Adsense

p[lacehoder
placehoolder
Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, January 10, 2011

The Most Common Mistake in C++ Programming

                After programming c++ for several years, i still make common mistakes that costs alot of time and stress.  Nevertheless, due to my experience, it is easy for me to figure out what this problem is most of the time.   For others who are just beginning c++, they can not afford of luxury of experience, thus they struggle for hours or days to try to find out the error.   Based on my days as a new programmer and on the experiences of several other beginner programmers, the most common but most catastrophic error is not having a return value for non-void functions.

                Most often, people will write functions that have a return value or int or string but in their code body, they do not return anything or sometimes just type “return”:

i.e
int me()
{…….
Return;
}
                This is fatal because even if you do not specify a return value, c++ will automatically and randomly return something of the specified return type.   Now, many people do this and with returns types like ints or floats, errors rarely occur, however, if you specify a function that returns a string and you do not return anything, you will get a lot of undefined errors or most of the time, you will get a seg fault.
http://en.wikipedia.org/wiki/Segmentation_fault
The reason is that a string is basically a array of character, one points to the next, and they take up a chunk of space of main memory.  Now, since you did not specify what string to return, the compiler will automatically return a string of arbitrary size and from and arbitrary location, now due to this randomized event, the compiler might choose a part in memory that is currently being allocated to another program, or event worse, a vital system service.  Thus, the OS intervenes, stops your program, and you get a seg fault.

                So the main theme here is to always return something, have a return value.  If you want your int function to return nothing, then type:
return 0;
if you want your string function to return nothing, then type :
return  “”;

this returns an empty string.   IF YOUR FUNCTIONS HAS A RETURN TYPE, THEN GIVE IT A RETURN VALUE, OTHERWISE  JUST WRITE A VOID FUNCTION!!
Returning values is a habit that you must get into, especially If you are writing large programs and want to minimize headaches.

How to Speed Up Your Computer

   I'm going to show you how to speed up your computer shutdown time signficantly.  This is for Windows Xp but should also work for Windows 7. First, open the registry editor.  To do this on windows XP, click start, run, then type in "regedit" in the box and click ok.  for Windows 7, click start -> search ->and type in "regedit". 
Disclaimer: only edit what i tell you to edit, do not edit anything else unless you what you are doing. Editing the wrong items will mess up your computer!


   First, we are going to edit the amount it that windows xp waits before kill open applications when the press the "shutdown" button.  to do this, go to "HKEY_CURRENT_USERControl PanelDesktop".  then double click "‘WaitToKillAppTimeout" and change the to 1000.  double click "HungAppTimeout" and change that value to 1000.

    Next, we are going to make it so Windows auto kills active applications.  this is very helpful, for example, when you press alt+ctrl+dlt to use the task manager to kill a non-responsive program, you will be prompted to confirm the killing off that app, by doing this, once you click "end process" that process will be killed immediately.  moreover, sometimes when you shut down your computer and walk away thinking that it has been shut down and come back 30 mins later to find that the computer is still on and you see a promt to"kill active applications", this is very annoying.  by enabling auto kill tasks, windows will automatically kill such apps.
to do this, double click "AutoEndTasks" and change the value to 1.

    The next step is to do this for every account on the computer, what we just did above was for your current account, we want to make it so that every account on the computer will shut down fast.  to do this, navigate to"HKEY_USERS.DEFAULTControl PanelDesktop" and change "‘WaitToKillAppTimeout" and "HungAppTimeout" to 1000 and "AutoEndTasks" to 1.  this should enable this tweak for every account.
   Finally, go to "HKEY_LOCAL_MACHINESystemCurrentControlSetControl" and double click "WaitToKillServiceTimeout" and change the value to 1000. 

Restart your computer and next time you shutdown, it should be much faster.
check out this video if you want  to see how to do it:

Related Posts Plugin for WordPress, Blogger...