Global Array or PVars
#1

I'm not looking for the fastest, I'm looking for the less cpu usage.
Global Array:
pawn Код:
enum PlayerInfo{
Kills,
Deaths,
Level
};
new Variable[MAX_PLAYERS][PlayerInfo];
PVars:
pawn Код:
SetPVarInt(playerid,"Kills",GetPVarInt(playerid, "Kills)+1);
Reply
#2

Mistake me if I'm wrong but wasn't there a test showing that Enums where microseconds faster than pvars?
Reply
#3

Just go with the PVars, having global variables will use unnecessary memory.
Reply
#4

The fastest - is less cpu usage, use global arrays for less cpu usage.
Reply
#5

PVars are slower than normal variables/arrays, but consume more memory depending on the operation, seeing as PVars do not allow you to allocate a static amount of memory.

Seeing as how 1 cell / a variable with only 1 cell consumes only 4 bytes of memory, I'd say that you're fine with either option, especially as PVars aren't that much slower.

PVars are also a lot more convenient as they reset when a player connects, but I personally use arrays/normal variables.
Reply
#6

Fastest = less CPU ussage, so your thread is like misspointing.
Reply
#7

I use a combination of both. When checking for admin levels, i use PVars since i can use it on different scripts. But mainly global arrays.
Reply
#8

Quote:
Originally Posted by [L3th4l]
Посмотреть сообщение
I use a combination of both. When checking for admin levels, i use PVars since i can use it on different scripts. But mainly global arrays.
I use a combination of both too, however I use PVars for things certain players won't require for checking, i.e: Use of a command restricted to a certain team, and seeing as how PVar integers return 0 if not set, they are extremely convenient.
Reply
#9

I did a test and I found that Normal Variables are faster than PVars.
pawn Код:
#include <a_samp>

#define ITTERATIONS  10000000

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}


public OnGameModeInit()
{
    new tick1,tick2;
    new playerid, Variable[MAX_PLAYERS];
    tick1 = tickcount();
    for(new i;i<ITTERATIONS;i++){
        if(Variable[playerid] == 0) continue;
    }
    printf("Normal Variable: %d", tickcount()-tick1);
    tick2 = tickcount();
    for(new i;i<ITTERATIONS;i++){
        if(GetPVarInt(playerid, "testing") == 0) continue;
    }
    printf("Per-Player Variable: %d", tickcount()-tick2);
    return 1;
}
Reply
#10

There was a test already about that posted somewhere. PVars ended up being ~3 times slower than normal variables.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)