Hi I have a some general questions, some are c others are c++ related.
So I'll just post them here in the c++ forum.
These question only relates to speed not so much design issues.
So far most of my programming has just been about making it work.
That is getting the program done fast and correct.
I haven't been concerned about speed and portability.
- I know it's good programming practice to make accessor's const.
But does it impact speed.
An example:
If I have a huge matrix class, which I will only read from, after I have instantiated the object.
Will I get any speed benifits from making the the accessors const. (making it nonmutable)? - Will I get any performance gains by using static keywords, where ever it's possible
- Will I get any performance gains by using const keywords, where ever it's possible
- If I made a uml diagram of my programs, they look relative alike. I never use the "smart" stuff, like protected and virtual function. Should I start looking into this. Or is it simply something that you use when you have to give a presentation. According to http://people.redhat.com/drepper/dsohowto.pdf the virtual functions are especially to avoid.
- scope of variables. I was always told to avoid using global variables, usually after being told never to use gotos. But other than the confusion of variable shadowing, what is so bad about it. Also recycling of temp vars.
An example:
Given a huge function, for the ease of of code reading, I normally just throw new variabels around, even though they are relatively easy to calculate from one another. Like b=2*a an so forth. Does the compiler now adays do this lowlevel optimization. - loops. I have some very long loops, these will make no sense to unroll. But the smaller ones. Say 5-10 times, should I manually unroll these, or are there no speed benefit from unrolling them.
- dynamic arrays vs fixed sized arrays. I mostly use dynamic arrays. But I read in the dsohowto, that these should be avoided. that is int[5] is prefereble to int*, since these can be fixed in the relocation table. Does it make a difference, or is it just academia
thanks in advance.