C++ - Global variable vs local variable read/write speed -


which fastest code among following ones?

void foo1 (int & a) {    = 10; } 

or

void foo2 (void) {    global_variable.a = 10; } 

(where global_variable global class element field 'a') ?

is there difference in variable access/write times between local , global variables?

it depend. (on program, on hardware, on compiler).

if matters, measure , choose fastest. if doesn't matter, choose clearest , least introduce errors.

(as others have noted, don't have local variable - have parameter passed reference.)


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -