Is it more expensive to use too many static variables instead of ordinary variables? if yes then how?
mazhar
2014-08-08 08:07:17 UTC
Is it more expensive to use too many static variables instead of ordinary variables? if yes then how?
Four answers:
mark_poc
2014-08-08 09:26:21 UTC
Static variables exist for the life of the program whereas local variables come and go as needed thus freeing up memory. So static variables use up more storage. Whether or not that's a problem depends on how much memory the system has and how many static variables are being used. In an embedded system where resources are at a minimum that could be a problem. But at the other extreme, if you have a PC with gigabytes of memory and you're only using a few static variables then it wouldn't matter at.
However, functions that use static variables should operate faster than local variables since local variables have to be pushed onto the stack every time the function is called, and the stack has to be cleaned up when the function returns, whereas static variables are already in place and ready to go. This would save on processing time.
So static variables are more expensive in terms of memory usage but less expensive in terms of processing time.
?
2014-08-08 08:24:57 UTC
It depends in what language you are coding in, to me I will say no because you aren't using anything but just code although you're writing more code.
?
2014-08-08 08:08:48 UTC
yes
mazhar
2014-08-08 08:10:25 UTC
update : please i need little detail ..why it is expensive??
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Search results for 'Is it more expensive to use too many static variables instead of ordinary variables? if yes then how?' (Questions and Answers)