Local or global string for mySQL queries -
MP2 - 17.01.2012
Which is more efficient in regards to memory?
pawn Код:
new query[..];
public callback()
{
format(query, ...);
mysql_query(query);
}
or
pawn Код:
public callback()
{
new query[..];
format(query, ...);
mysql_query(query);
}
?
Re: Local or global string for mySQL queries -
Scenario - 17.01.2012
I have always been under the impression that local variables are better. I could be wrong, but I don't think I am!
Re: Local or global string for mySQL queries -
Gerira Gaijin - 17.01.2012
I believe that too, because global variables are active all the time, I mean server has to keep them all the time, while local variables get deleted after the code is executed.
Re: Local or global string for mySQL queries -
Kar - 17.01.2012
global I believe
Re: Local or global string for mySQL queries -
Gamer_Z - 17.01.2012
I didn't research it but it sounds logically that variables created and then destroyed let you have more ram, however you have some performance loss.
PAWN is single threaded so if you're going to do a thousand times new string[256]; in each callback, why not make one global string? saves performance and time.(+amx size will be smaller)
Re: Local or global string for mySQL queries -
Gerira Gaijin - 17.01.2012
Quote:
Originally Posted by Gamer_Z
I didn't research it but it sounds logically that variables created and then destroyed let you have more ram, however you have some performance loss.
PAWN is single threaded so if you're going to do a thousand times new string[256]; in each callback, why not make one global string? saves performance and time.(+amx size will be smaller)
|
That's a good point there, I never thought of that. I may even use it in my scripts.
Re: Local or global string for mySQL queries -
Corello2010 - 17.01.2012
Yea', I decided to use a Global String in my script for most of my MySQL queries. Not sure if it's faster or not but it appears that way, I could be wrong though.
Re: Local or global string for mySQL queries - T0pAz - 18.01.2012
Quote:
Originally Posted by Gamer_Z
I didn't research it but it sounds logically that variables created and then destroyed let you have more ram, however you have some performance loss.
PAWN is single threaded so if you're going to do a thousand times new string[256]; in each callback, why not make one global string? saves performance and time.(+amx size will be smaller)
|
this!
Re: Local or global string for mySQL queries -
thimo - 18.01.2012
Quote:
Originally Posted by Gamer_Z
I didn't research it but it sounds logically that variables created and then destroyed let you have more ram, however you have some performance loss.
PAWN is single threaded so if you're going to do a thousand times new string[256]; in each callback, why not make one global string? saves performance and time.(+amx size will be smaller)
|
Wouldnt it get bugged when 2 players use it at same time?
Re: Local or global string for mySQL queries -
Gamer_Z - 18.01.2012
Quote:
Originally Posted by thimo
Wouldnt it get bugged when 2 players use it at same time?
|
pawn Код:
new string[256];
public OnPlayerUpdate(playerid)
{
format(string,256,"Hello %d",playerid);
SendClientMessage(playerid,-1,string);
return 1;
}
Will work totally fine.