i'm running simulation takes time run , want improve that. understood, passing value function means that value copied slow. there way include functions in dedicated file won't need copy values?
i don't mind "wrong programing" (global variable, public access etc.) gain speed.
thanks
edit: when started project, tested several loops. counted processor style between start , stop of loop of kind:
int = 0; while (i < 10000000){ = dostuff(i); //or dostuff(); } int dostuff(i){ return i++; } int dostuff(){ return i++; }
i'm pretty sure dostuff() case 10 times faster. have changed previous code global variables , direct access ("wrong programming") , improved runtime significantly. tried use references had inherent problem prevented me doing (i don't remember was). anyhow, i'm playing around gprof now.
you use references. if have function:
void examine(bighairyobject o) { cout << o.data[1234]; /* example */ }
you can avoid copy passing reference object:
void examine(bighairyobject & o) { cout << o.data[1234]; /* use identical */ }
the downside of this, referring original object, not copy of it. so, if modify o
(in example), modifying caller's object.
if want promise not modify object (and in case, reference copy), use const
keyword:
void examine(const bighairyobject & o) { cout << o.data[1234]; /* use identical */ // o.data[1234] = 5; // cause compile error. }
Comments
Post a Comment