Code optimization questions
#1

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

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

So you mean static == new. Both give same shit?
Reply
#4

No. Look at example - static variable is remembered, while variable created with new is deleted.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)