[Duda] Variables PVars -
oOFotherOo - 26.11.2012
Buenas amigos de SAMP quisiera saber si me pueden responder esta pequeсa duda:
їLas variables PVars procesan mas rapido que las tradicionales enums?
Quisiera saber si implementando PVars se obtendria mayor optimizaciуn.
Muchas gracias.
Un saludo.
Respuesta: [Duda] Variables PVars -
TheChaoz - 26.11.2012
El unico momento en el que se justifica la utilizacion de PVars es en la interaccion de scripts (es decir que los scripts obtienen datos de otros scripts para los jugadores). Si no es este tu caso, te sugiero utilizar los arrays normales.
Respuesta: [Duda] Variables PVars -
oOFotherOo - 26.11.2012
Quote:
Originally Posted by the_chaoz
El unico momento en el que se justifica la utilizacion de PVars es en la interaccion de scripts (es decir que los scripts obtienen datos de otros scripts para los jugadores). Si no es este tu caso, te sugiero utilizar los arrays normales.
|
Muchas gracias, pero lei en un tutorial que las PVars consumen menos recursos y que puedes guardar datos tipos string sin necesidad de definirla ya que se asigna automaticamente, tambien que son dinamicas como usted acabo de decir osea que puedo lo puedo usar tanto en FS como en el GM conservando los mismos valores.
PD: En fin, їOptimiza mas el script o no?
Muchas gracias.
Un saludo.
Respuesta: [Duda] Variables PVars -
TheChaoz - 26.11.2012
La respuesta es no, no son mejores en cuanto a optimizacion. Explicado de una forma simple, esto se debe a que cuando se utilizan variables/arrays normales se guardan directo en la memoria y se accede directamente a la misma. En cambio cuando se utilizan PVars, el servidor accede a la memoria donde se guardo el nombre de dicha variable, de alli toma el puntero almacenado y recien ahi lee el contenido de dicha variable.
Explicacion grafica:
Variables normales:
pawn Код:
new miarray[10];
miarray = "contenido";
Код:
Memoria:
[c|o|n|t|e|n|i|d|o|\0]
Variables PVar:
pawn Код:
SetPVarString(playerid, "Extra", "contenido");
Код:
Memoria:
1є Busca en la memoria el puntero correspondiente a la variable "Extra" del jugador.
[E|x|t|r|a|\0] => Obtiene el puntero
2є Carga el contenido correspondiente a la direccion del puntero.
[c|o|n|t|e|n|i|d|o|\0]
Respuesta: [Duda] Variables PVars -
oOFotherOo - 26.11.2012
Muchas gracias en verdad las arrays son mas rapidas, aunque se llevan poco en diferencia.
Test:
pawn Код:
#include <a_samp>
#undef MAX_PLAYERS
#define MAX_PLAYERS (1000000)
enum pData
{
array,
};
new PlayerInfo[MAX_PLAYERS][pData];
public OnFilterScriptInit()
{
//==========================================================================
new
dCount = GetTickCount();
for(new i; i < MAX_PLAYERS; ++i)
{
PlayerInfo[i][array] = 1;
}
printf("[Array] Funciуn: %d - Tiempo: %d", MAX_PLAYERS,(GetTickCount() - dCount));
//==========================================================================
new
bCount = GetTickCount();
for(new i; i < MAX_PLAYERS; ++i)
{
SetPVarInt(i, "array", 1);
}
printf("[PVars] Funciуn: %d - Tiempo: %d", MAX_PLAYERS,(GetTickCount() - bCount));
//==========================================================================
return true;
}
Respuesta: [Duda] Variables PVars -
Fluid016 - 26.11.2012
Quote:
Originally Posted by oOFotherOo
Muchas gracias en verdad las arrays son mas rapidas, aunque se llevan poco en diferencia.
Test:
pawn Код:
#include <a_samp>
#undef MAX_PLAYERS #define MAX_PLAYERS (1000000)
enum pData { array, }; new PlayerInfo[MAX_PLAYERS][pData];
public OnFilterScriptInit() { //==========================================================================
new dCount = GetTickCount();
for(new i; i < MAX_PLAYERS; ++i) { PlayerInfo[i][array] = 1; }
printf("[Array] Funciуn: %d - Tiempo: %d", MAX_PLAYERS,(GetTickCount() - dCount));
//==========================================================================
new bCount = GetTickCount(); for(new i; i < MAX_PLAYERS; ++i) { SetPVarInt(i, "array", 1); } printf("[PVars] Funciуn: %d - Tiempo: %d", MAX_PLAYERS,(GetTickCount() - bCount));
//========================================================================== return true; }
|
se llevan poco en diferencia (ni se si de esa manera se estaria comprobando bien) pero me tarda mбs el array
Re: Respuesta: [Duda] Variables PVars -
Daniel-92 - 26.11.2012
Quote:
Originally Posted by oOFotherOo
Muchas gracias en verdad las arrays son mas rapidas, aunque se llevan poco en diferencia.
Test:
pawn Код:
#include <a_samp>
#undef MAX_PLAYERS #define MAX_PLAYERS (1000000)
enum pData { array, }; new PlayerInfo[MAX_PLAYERS][pData];
public OnFilterScriptInit() { //==========================================================================
new dCount = GetTickCount();
for(new i; i < MAX_PLAYERS; ++i) { PlayerInfo[i][array] = 1; }
printf("[Array] Funciуn: %d - Tiempo: %d", MAX_PLAYERS,(GetTickCount() - dCount));
//==========================================================================
new bCount = GetTickCount(); for(new i; i < MAX_PLAYERS; ++i) { SetPVarInt(i, "array", 1); } printf("[PVars] Funciуn: %d - Tiempo: %d", MAX_PLAYERS,(GetTickCount() - bCount));
//========================================================================== return true; }
|
el test estб mal, las pvars no funcional con ids arriba de max_players definido en en server.cfg ademбs que el jugador debe estar conectado para poderle asignar un valor.
Respuesta: [Duda] Variables PVars -
oOFotherOo - 26.11.2012
Perdуn Daniel-92 tiene razуn aqui el test correcto:
pawn Код:
#include <a_samp>
#define MAX_TIME (1000000) //loops para teste
enum pData
{
array,
};
new PlayerInfo[MAX_TIME][pData];
public OnFilterScriptInit()
{
//==========================================================================
new
dCount = GetTickCount();
for(new i; i < MAX_TIME; ++i)
{
PlayerInfo[i][array] = 1;
}
printf("[Array] Funciуn: %d - Tiempo: %d MS", MAX_TIME,(GetTickCount() - dCount));
//==========================================================================
new
bCount = GetTickCount();
for(new i; i < MAX_TIME; ++i)
{
SetPVarInt(i, "array", 1);
}
printf("[PVars] Funciуn: %d - Tiempo: %d MS", MAX_TIME,(GetTickCount() - bCount));
//==========================================================================
return true;
}
Un saludo.
Re: [Duda] Variables PVars -
Daniel-92 - 27.11.2012
No deberias usar "i" como id porque estarias pasando los ids maximos en samp y ademбs que tendrian que estar conectados 1000000 jugadores en el servidor para que de el resultado bien, lo mejor es usar un ID fijo por ejemplo el 0.
pawn Код:
new bCount = GetTickCount();
for(new i; i < MAX_TIME; ++i) {
SetPVarInt(0, "array", 1); //con el id 0
}
printf("[PVars] Funciуn: %d - Tiempo: %d MS", MAX_TIME,(GetTickCount() - bCount));
para poder testear esto deberia haber en el servidor un jugador con la id 0.
PD: El test me dio como resultado: variables normales 78 ms | pvars 269 ms
Respuesta: [Duda] Variables PVars -
DesingMyCry - 27.11.2012
Daniel-92, se te olvido quitar el bucle? o piensas que eso va asн?