|
Author
|
Message
|
|
Senior Member
|

11-05-2011
, 15:33
Optimizing Plugins
|
#1
|
I read something about optimizing plugins which i couldn't understand
Quote:
Likewise, it is equally important to avoid declaring arrays inside of loops. Consider the following block of code:
for (new i=0; i<num; i++)
{
new message[255], name[32], player
player = players[i]
get_user_name(player, name, 31)
format(message, 254, "Hello, %s", name)
}
If there are 32 players, this loop will actually resize and zero out over 1K of memory thirty two times in a row. Not good! However, on the other hand, it's nice that the message is zeroed out for us each time. Tip: you often only need to zero out the first character of a string. This will make the entire string empty. The code below is much more efficient:
new message[255], name[32], player
for (new i=0; i<num; i++)
{
player = players[i]
name[0] = '^0'
message[0] = '^0'
get_user_name(player, name, 31)
format(message, 254, "Hello, %s", name)
}
This has the effect of safely making the string empty beforehand, as well as largely reducing a lot of run-time overhead.
|
if somone would explain it with easier english or in another way it would be good.
|
|
|
|