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

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -