RE: [Dev-C++] Use of const qualifier
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2002-11-01 20:56:36
|
Sorry, no correct answer on that one :-( Depends on compiler, processor and what the calling function did. If only targeted for a very specific machine, you have to time execution with the two alternatives, else leave the function as it is. Without relying on assembler - which is definitely CPU-specific - you can't force static variables to be placed at an optimum alignment, and you can't align the auto variables on the stack. The auto is probably the best all-around alternative, since it allows the compiler to use floating point registers. A static variable implies the survival of the value to the next call, which will probably reduce the effectivity of the compiler optimization step. /Per W On Fri, 1 Nov 2002, Scott Williams wrote: > Thanks for the reply--very helpful. You might know the answer to a related > question. . . > > I have a math-intensive subroutine that is called millions of times (yes, > millions) by a numerical algorithm. Currently, all of the variables in this > subroutine are of automatic extent. Would there be any efficiency gained by > instead giving them static extent? Each call to the subroutine is > independent so retaining values across calls is not an issue. Rather, this > is a question of how the memory access itself is handled. > > Thanks. > Scott > > > -----Original Message----- > From: Abhijit Shylanath [mailto:mu...@gm...] > Sent: Thursday, October 31, 2002 5:30 PM > To: se...@al...; Dev-C++ Mailing List > Subject: Re: [Dev-C++] Use of const qualifier > > > > where myfunc uses the values of x and the array members of y but doesn't > > change them. Is there then an efficiency (speed) to be gained by instead > > declaring: > > > > double myfunc(const double x, const double *y)? > > More than speed, the const qualifier is for debugging. It prevents the > programmer from inadvertently changing the values of certain variables. Some > new optimizing compilers also use it to align memory more efficiently. > > ___________________________________________________________ > > Abhijit Shylanath > > E-mail: mu...@gm... || ibr...@bi... > Web-site: http://mudeth.tripod.com/ > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: See the NEW Palm > Tungsten T handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |