SA-MP Forums Archive
Global Array or PVars - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Global Array or PVars (/showthread.php?tid=216597)



Global Array or PVars - anonymousx - 25.01.2011

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);



Re: Global Array or PVars - Not available - 25.01.2011

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


Re: Global Array or PVars - Grim_ - 25.01.2011

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


Re: Global Array or PVars - iggy1 - 25.01.2011

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


Re: Global Array or PVars - Calgon - 25.01.2011

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.


Re: Global Array or PVars - The_Moddler - 25.01.2011

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


Re: Global Array or PVars - [L3th4l] - 25.01.2011

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.


Re: Global Array or PVars - Calgon - 25.01.2011

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.


Respuesta: Global Array or PVars - anonymousx - 15.02.2011

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;
}



Re: Global Array or PVars - Macluawn - 15.02.2011

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