Local or global string for mySQL queries
#1

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);
}
?
Reply
#2

I have always been under the impression that local variables are better. I could be wrong, but I don't think I am!
Reply
#3

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.
Reply
#4

global I believe
Reply
#5

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)
Reply
#6

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.
Reply
#7

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.
Reply
#8

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!
Reply
#9

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?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)