Which is better to do? enum in memory or a variable every time?
#1

Hello!

Is better to do, this:

PHP код:
enum ePlayerData{
accountid,
score,
money,
IP[17],
SERIAL[42],
deaths
}
new 
PlayerData[MAX_PLAYERS][ePlayerData];
stock StorePlayerSerial(iPlayerID)
{
    new 
        
szSerial[41]; // 40 + \0
 
    
gpci(iPlayerIDszSerialsizeof(szSerial));
    
memcpy(PlayerData[iPlayerID][SERIAL], szSerial0strlen(szSerial) * 442);
    return 
szSerial;
}
//here it's not possible to return PlayerInfo[playerid][IP] because it will return a wrong value, I know. However I can use the PlayerInfo[playerid][IP] variable in the whole gamemode without problems, I have tested it.
stock StorePlayerIP(playerid)
{
    
GetPlayerIp(playeridPlayerInfo[playerid][IP], 17);
    return 
1;

So I can use the IP and SERIAL variables later at any time using
PHP код:
PlayerData[playerid][IP
or this way:
PHP код:
stock GetPlayerIP(playerid)
{
       new  
ipaddr[17];
       
GetPlayerIp(playeridipaddrsizeof(ipaddr));
       return 
ipaddr;
}
stock GetPlayerSerial(iPlayerID)
{
    new  
szSerial[42];
    
gpci(iPlayerIDszSerialsizeof(szSerial));
    return 
szSerial;

I think the second way uses more memory because it creaste a string of 42 bytes (serial) everytime, but I'm not sure.

Meaning of ram memory/cpu/etc.. which is better to use and why?

Thank you.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)