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 ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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.
|
|
|||
|
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 |
![]() |
| Thread Tools | |
|
|
|
||||
| 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 |