View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-13-2020 , 10:49   Re: Advanced GlowMenu v2.0.0 [12/04/2020]
Reply With Quote #22

Quote:
What do you mean with this? could you give me an example? I get the fact that the array size will never change, but why do i need to cache it?
for(initialization; condition; step)
In a loop, the condition is tested on each iteration.

Your condition is something like: i < ArraySize(). What happens is after each iteration the plugin has to call ArraySize in order to be able to compare it with "i".
If you cache it into a variable then you can use that in the loop condition and avoid calling the native for each step.

Code:
i = 0: execute your code, call ArraySize, compare with i, increment
i = 1: execute your code, call ArraySize, compare with i, increment
...
i = k: execute your code, call ArraySize, compare with i, increment
...

With caching:
i = 0: execute your code, compare variable with i, increment
i = 1: execute your code, compare variable with i, increment
...
i = k: execute your code, compare variable with i, increment
...
You don't need to do that for loops using sizeof and regular arrays, because their size is known at compile time.
__________________

Last edited by HamletEagle; 04-13-2020 at 10:54.
HamletEagle is offline