Creating static inside loop
Code:
Code:
I thought about using this to prevent wasting that (32 CELLS!!!! of) memory unless there actually is a count. But if it comes at the cost of CPU load it's useless. |
Re: Creating static inside loop
Second.
Quote:
I don't know if this also аpplies to statics, but I think it's something sort of. |
Re: Creating static inside loop
It's essentially the same thing except for scope. Generally, if you create the variable inside the loop, it cannot be used outside the loop. The fact that it is static will mean there won't be any significant performance degradation after it has run once. Regardless, it always best to stick to the "never create variables inside a loop" recommendation.
|
Re: Creating static inside loop
I suggest static type of variables to be declared at the beginning of a function that executes really frequently.
PHP Code:
|
Re: Creating static inside loop
Let me be more specific. I understand the scope and I know that the memory allocation for a static is not released until the plugin is unloaded. That is not the question.
Is there some kind of function that checks if the memory has been allocated that will run every time i try to create the static inside of the loop? Will this create extra work during runtime at each loop execution that should be avoided? I'm not using it either way. It will only make things more complicated. Now it's just curiosity. |
Re: Creating static inside loop
I wouldn't worry about it since you shouldn't ever do it.
|
Re: Creating static inside loop
Static variables are stored in the DAT section of the plugin and are present for the entirety of the plugin's lifetime, which means that allocation happens automatically with loading your plugin. It should be obvious by their behavior that, even though they are scoped in the code syntax and the compiler enforces this, they technically are not local to the function. They work exactly the same as global variables in this respect - you just can't access them the same way through code.
|
Re: Creating static inside loop
Thank you.
|
Re: Creating static inside loop
Quote:
|
All times are GMT -4. The time now is 21:02. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.