Concern: global or local string variable scope?
#1

Which approach should I take in order to make my server run smoother. What I mean is, should I use only one variable throughout my code? The reason I'm asking is because I sometimes am forced to define a string variable with 256+ cells to read long file lines.

Using this:
Code:
new str[100];
public fTest(arg)
{
format(str,sizeof str,"%d", arg);
return str;
}
public fTest2(arg)
{
format(str,sizeof str,"%d", arg);
return str;
}
Instead of:
Code:
public fTest(arg)
{
new str[100];
format(str,sizeof str,"%d", arg);
return str;
}
public fTest2(arg)
{
new str[100];
format(str,sizeof str,"%d", arg);
return str;
}
... and so on
Reply
#2

I would declare it as static stock (well maybe not stock, because you are going to end up using it which ends the point of declaring it as stock) in local scope because 1) static would declare it only once and 2) Suppose you read a file when a player connects and disconnects, and two players connect and disconnect at the same time, then it would cause some unwanted results. So, better to be safe! EDIT: Didn't see the reply above.
Reply
#3

Well, you guys bring up some good points to the table. Do you have any other suggestions on how I can improve?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)