Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Local or global...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 44719 of 47995
Post > Topic >>

Local or global variables in frequently called functions?

by danep2 <danepowell@[EMAIL PROTECTED] > Apr 13, 2008 at 01:56 PM

Let me start by saying that this is more a question about principle
than practice - with the speed of today's computers it's probably
rarely an actual issue.  Still I'd like to know...

If I have a function that is called thousands of times per second, it
seems to me that, performance-wise, it would be best to make all
variables used in it global, so that memory for them doesn't have to
be allocated and released with each call.  However, I know this
clutters up the name space and can make the code more bug-prone.

Would it ever make sense to use global variables over local ones in
this situation? Would the same answer apply to threads instead of
functions?  Thanks for satisfying my curiosity!
 




 2 Posts in Topic:
Local or global variables in frequently called functions?
danep2 <danepowell@[EM  2008-04-13 13:56:49 
Re: Local or global variables in frequently called functions?
=?UTF-8?B?RXJpayBXaWtzdHL  2008-04-13 21:17:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 21:21:50 CDT 2008.