Thread: Re: [Dev-C++] Use of const qualifier
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2002-11-02 05:14:23
|
> > Yes. Also if you can make it easy to be inlined things will be more > > better. > > Inlining a function is decided by the compiler. Functions with loops, etc. > are generally not inlined, so this won't be of much help. You can achieve > the same end by simply eliminating the function (moving all of the code into > the main routine). This will remove the overhead of function calls and > memory allocation (which should help a lot in this case). This should be a > case of code-elegance versus execution-speed. Also consider generating > look-up tables of sine and cos. There are a lot of articles on the web about > optimizing programs. I remember one that spoke in explicit detail about how > memory can be optimized... unfortunately, I don't remember saving it. Google > helps. This site: http://www.numerix-dsp.com/c_coding.html says that static variables help. ___________________________________________________________ Abhijit Shylanath E-mail: mu...@gm... || ibr...@bi... Web-site: http://mudeth.tripod.com/ |
|
From: Per W. <pw...@ia...> - 2002-11-02 10:27:36
|
1 - Declaring a function inline doesn't work for function pointers, or when writing mixed-language programss. 2 - Eliminating the function to remove the function call obviously doesn't work either for same reason as above. 3 - The link referenced below is written with DSP processors in mind. Some optimization work. A lot of the suggestions are questionable on a general-purpose processor. /Per W On Sat, 2 Nov 2002, Abhijit Shylanath wrote: > > > > > Yes. Also if you can make it easy to be inlined things will be more > > > better. > > > > Inlining a function is decided by the compiler. Functions with loops, etc. > > are generally not inlined, so this won't be of much help. You can achieve > > the same end by simply eliminating the function (moving all of the code > into > > the main routine). This will remove the overhead of function calls and > > memory allocation (which should help a lot in this case). This should be a > > case of code-elegance versus execution-speed. Also consider generating > > look-up tables of sine and cos. There are a lot of articles on the web > about > > optimizing programs. I remember one that spoke in explicit detail about > how > > memory can be optimized... unfortunately, I don't remember saving it. > Google > > helps. > > This site: > > http://www.numerix-dsp.com/c_coding.html > > says that static variables help. > > ___________________________________________________________ > > 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 > |
|
From: Abhijit S. <mu...@gm...> - 2002-11-02 15:27:23
|
> 1 - Declaring a function inline doesn't work for function pointers, > or when writing mixed-language programss. > > 2 - Eliminating the function to remove the function call obviously doesn't > work either for same reason as above. > > 3 - The link referenced below is written with DSP processors in mind. Some > optimization work. A lot of the suggestions are questionable on a > general-purpose processor. Most of the stuff is about C in general, so it should work on any C compiler. At least the point about inlining is with regard to C, so I thought I'd link to my source. ___________________________________________________________ Abhijit Shylanath E-mail: mu...@gm... || ibr...@bi... Web-site: http://mudeth.tripod.com/ |
|
From: Ioannis V. <no...@ho...> - 2002-11-02 20:28:23
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Per Westermark > Sent: Saturday, November 02, 2002 12:27 PM > To: Abhijit Shylanath > Cc: 'Dev-C++ Mailing List' > Subject: Re: [Dev-C++] Use of const qualifier > > > 1 - Declaring a function inline doesn't work for function pointers, > or when writing mixed-language programss. Usually yes. There is no rule however. For this reason, in C++ it is better to pass a type argument with static member functions. Or use function objects. > 2 - Eliminating the function to remove the function call > obviously doesn't > work either for same reason as above. > > 3 - The link referenced below is written with DSP processors > in mind. Some > optimization work. A lot of the suggestions are questionable on a > general-purpose processor. I am very busy these last days so i have no much time to post messages on the list. Regarding efficiency & C++, the best thing one can do is to use the high level constructs and do not bother about low level details. So for example use strings and pass them by reference and do not bother for the details. Regarding C, the compiler can perform whatever optimisations it likes. As a general rule one must try to avoid repeative function calls (like calling the same function 1 million times). Regarding variables with exception of large struct types, the time cost of creating and destroying variables in nowadays machine can be ignored. For a large struct, using a static struct variable can help. Again, one must think of run time optimisations when he sees that his code is unacceptable slow. Like for(size_t i=0; i<strlen(s); i++) /* ... */ If the compiler is clever, it may avoid calling strlen(), strlen(s) times. If we see that the code crawls (and only then), one can think of optimisations like: const size_t SLENGTH=strlen(s); for(size_t i=0; i<SLENGTH; i++) /* ... */ In general, do not think of optimising something without having a problem with it. Also usually run-time optimisation adds space cost, and space optimisation adds runtime cost. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |