Raised This Month: $ Target: $400
 0% 

Store the output of a loop in one string.


Post New Thread Reply   
 
Thread Tools Display Modes
naris
AlliedModders Donor
Join Date: Dec 2006
Old 02-04-2010 , 17:10   Re: Store the output of a loop in one string.
Reply With Quote #11

Quote:
Originally Posted by bstyle View Post
Ok and why is this method better than using StrCat?
Since StrCat() itself calls Fromat(), you are calling Format() twice, once to format the string and then again to concatenate it to the big string, which also increases the amount of work done since it has to physically copy the new string to the end of the big string.

Using the method I posted, Format is only called once to tack the new string onto the end of the existing big string. It also avoids having to copy the contents of the new string to the end of the big string after formatting it, since it is already there.
naris is offline
bstyle
Member
Join Date: Nov 2009
Old 02-04-2010 , 17:48   Re: Store the output of a loop in one string.
Reply With Quote #12

Ok, thanks for the help.
bstyle is offline
DieTeetasse
Senior Member
Join Date: Jul 2009
Old 02-05-2010 , 05:24   Re: Store the output of a loop in one string.
Reply With Quote #13

Quote:
Originally Posted by naris View Post
WTF are you talking about? Having the "new len" inside the loop is perfectly reasonable.
Calm down. Didn't know that it is possible in Pawn to redefine a variable inside a loop.
But why are you allocating space again and again, instead of defining len before?
__________________
DieTeetasse is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 02-05-2010 , 11:32   Re: Store the output of a loop in one string.
Reply With Quote #14

I believe Pawn is smart enough to allocate the memory only once. I still define my variables outside of loops as well, though. Better practice for other languages that aren't so forgiving.
__________________
Greyscale is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 02-06-2010 , 20:19   Re: Store the output of a loop in one string.
Reply With Quote #15

I'm pretty sure it would reallocate it every time unless it was defined as 'static'.
bl4nk is offline
Reply



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 19:00.


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