Code optimization questions - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Code optimization questions (
/showthread.php?tid=364947)
Code optimization questions -
Gangs_Rocks - 01.08.2012
Okay, I'm making a SII/MYSQL based saving + admin system and I'm optimizing the code now.
So, I want to know some stuff:
What is the difference between new and static? Which one should be used to set global variables and which should be used to get names and etc.?
+ Is there an easier way to create strings instead of creating static fuckedString[CELLSIZEHERE];? Like a simpler way which would be more effective.
I'm trying to make a really efficient system so I need to know the following ^^.
Basically:
would this be efficient
pawn Код:
// On the top of the script
new GlobalString[220];
// Under some function or cmd
format(GlobalString, sizeof(GlobalString), "SHITHERE %d %d", crap, crap);
OR
pawn Код:
// In all functions and cmd
new gString[120];
format(gString, sizeof(gString), "CRAP CRAP CRAP");
better?
AND
is
pawn Код:
// Below every function/cmd
new gString[120];
format(gString ... );
BETTER OR
pawn Код:
static gString[120];
format(gString ... );
Re: Code optimization questions -
Misiur - 01.08.2012
You can't quite compare GlobalString with gString, because - well, one is available globally, and second one is only in local scope. You can accidentaly leak some data you don't want to share between functions. Local variables are destroyed once out of scope, so it won't give you some performance ultraboost.
pawn Код:
for(new i = 0; i < 5; ++i) {
new j = 0;
static k = 0;
printf("Value of new: %d, value of static: %d", j, k);
k++, j++;
}
You'll get:
Quote:
Value of new: 0, value of static: 0
Value of new: 0, value of static: 1
Value of new: 0, value of static: 2
Value of new: 0, value of static: 3
Value of new: 0, value of static: 4
|
Variable created with new is destroyed just after it's not in scope.
Re: Code optimization questions -
Gangs_Rocks - 01.08.2012
So you mean static == new. Both give same shit?
Re: Code optimization questions -
Misiur - 01.08.2012
No. Look at example - static variable is remembered, while variable created with new is deleted.