Raised This Month: $ Target: $400
 0% 

Optimizing Plugins


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Dr7sTyLe
Senior Member
Join Date: Dec 2010
Old 11-05-2011 , 15:33   Optimizing Plugins
Reply With Quote #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.
Dr7sTyLe is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode