Exforsys

Online Training

Want to Know the Reason

This is a discussion on Want to Know the Reason within the C and C++ forums, part of the Programming Talk category; I declared an auto variable x and print it loping through 1 to 1000 times in my program 1. In ...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-29-2007, 11:35 AM
Senior Member
 
Join Date: Apr 2006
Posts: 145
Rahulbatra is on a distinguished road
Want to Know the Reason

I declared an auto variable x and print it loping through 1 to 1000 times in my program 1. In my program2 I declared a register variable x and print it loping through 1 to 1000 times. Though both gives the same output from 1 to 1000 I want to know which works faster and which is better in performance. Kindly explain the reason for the same.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-30-2007, 06:30 AM
Junior Member
 
Join Date: May 2007
Posts: 9
hvg_99 is on a distinguished road
Reason

Hi,

Since an auto variable is stored in memory and a register variable is stored in a CPU Register in the hopes of enhancing performance by minimizing access time. . Values stored in a register is executed faster than one stored in memory. However, the compiler is not required to honor this request. Because of the limited size and number of registers available on most systems, few variables can actually be put in registers. If the compiler does not allocate a machine register for a register object, the object is treated as having the storage class specifier auto.

Register access is faster than memory access. The register storage class is a hint to the compiler that the variable will be heavily used. Storing data there gets rid of the overhead of retrieving the data from normal memory. This memory is quite small compared to normal memory though so only a few variables can be stored there.

Point to be noted:

* A register does not have an address and & operator cannot be used/applied
* One cannot use a pointer to a register storage class specifier


I hope i have cleared your doubt. For further clarifications you can mail back.

Gayatri
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Reason for Compiler Error Adrian C and C++ 1 05-10-2007 09:20 AM
Reason for Reduced Performance caradoc ASP 1 05-08-2007 04:43 PM
Kindly Provide the Reason caradoc Coldfusion 0 01-14-2007 11:06 AM
Reason for Output cyrus C and C++ 1 01-14-2007 11:02 AM
Kindly provide the Reason Angela Oracle Database 2 12-28-2006 03:48 PM


All times are GMT -4. The time now is 12:33 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.