SA-MP Forums Archive
[Include] rFile - Faster than y_ini - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] rFile - Faster than y_ini (/showthread.php?tid=197865)



rFile - Faster than y_ini - Diler - 10.12.2010

Author: RPS (aka Diler)
Version: 1.0 R2
Last Update: 06.11.2010

It is a fast and simple system file operations


Functions:

Код:
Read(playerid) - function read a player file (use in OnPlayerConnect/Spawn)
Save(playerid) - function saves the data players (use in OnPlayerDisconnect)
Delete(playerid) - function removes the file player (use after Save)
DeleteOption(playerid, option[]) - function removes option in player file

ReadFile(const filename[], const ID) - function read a file
SaveFile(const filename[], const ID) - function save a file
DeleteFile(filename[]) - function removes the file
DeleteFileOption(const ID, option[]) - function removes option in file

rSetStr(playerid, option[], definition[]) - function save string to file
rSetInt(playerid, option[], definition) - functtion save integer to file
rSetFloat(playerid, option[], Float:definition) - function save float to file

rGetStr(playerid, option[]) - function returns the definitions of the options
rGetInt(playerid, option[]) - function returns the definitions of the options
rGetFloat(playerid, option[]) - function returns the definitions of the options
IsSet(playerid, option[]) - function returns when it finds an option, 0 if not
How to use ?
Simple code:
Код:
#include <a_samp>
#include <rFile>

public OnFilterScriptInit()
{
    #define ID 51
    ReadFile("rFile.ini", ID);
    rSetStr(ID, "Str", "test");
    rSetInt(ID, "Int", 1);
    rSetFloat(ID, "Float", 1.234);
    printf("%s | %d | %f", rGetStr(ID, "Str"), rGetInt(ID, "Int"), rGetFloat(ID, "Float"));
    DeleteFileOption(ID, "Str");
    SaveFile("rFile.ini", ID);
    return 1;
}
and...
Код:
public OnPlayerConnect(playerid)
{
    Read(playerid);
    rSetInt(playerid, "CountConnect", rGetInt(playerid, "CountConnect")+1);
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    Save(playerid);
    return 1;
}
Comparison
Код:
#include <a_samp> 
#include <YSI\y_ini> 
#include <rFile> 

#define MAX 1000 
public OnFilterScriptInit() 
{ 
    new 
        str[128], 
        s = GetTickCount(); 

    new INI:tt = INI_Open("y_ini.ini"); 
    for(new i; i < MAX; i++) 
    { 
       format(str, sizeof str, "test%d", i); 
       INI_WriteString(tt, str, "test"); 
    } 
    INI_Close(tt); 
    printf("[Y_INI]: %d", GetTickCount()-s); 

    s = GetTickCount(); 
    ReadFile("rFile.ini", 50); 
    for(new i; i < MAX; i++) 
    { 
       format(str, sizeof str, "test%d", i); 
       rSetStr(50, str, "test"); 
    } 
    SaveFile("rFile.ini", 50); 
    printf("[R_FILE]: %d", GetTickCount()-s); 
    return 1; 
}
Result:
The first time - 458 (y_ini) vs 204 (rFile) [ms]
The second time - 718 (y_ini) vs 87 (rFile) [ms]

Download
Pastebin -> http://pastebin.com/4DmWp8Bk


Код:
#define MAX_PLAYERSS 50
Replace number to server slots !!

Thank you for your time and sorry for my bad english


Re: rFile - Faster than y_ini - Wennicke - 10.12.2010

Is it possible, you can proof that it's faster?


Re: rFile - Faster than y_ini - Diler - 10.12.2010

Added


Re: rFile - Faster than y_ini - GaGlets(R) - 10.12.2010

Probably its simple test but for large sessions it will be slow - isnt it?

For about 100 players how fast it would save?

Edit: its realy simple saving... and oyu are not using player file saving (y_ini) but simple file. .


Re: rFile - Faster than y_ini - Gavibro - 10.12.2010

new FileVar[MAX_FILES][10000];
why 10000??!?!?!?!? I think MAX_FILES is aka MAX_PLAYERS and 10000 is 'cells' or wtf it's called .


Re: rFile - Faster than y_ini - Grim_ - 10.12.2010

Player files are the same as regular INI files, it just depends how you set them up with different keys.

@Gabrivo: A maximum file's size (as in characters written) isn't necessarily going to be MAX_PLAYERS or 500.


Re: rFile - Faster than y_ini - RyDeR` - 10.12.2010

Maybe faster, but not as useful.


Re: rFile - Faster than y_ini - Diler - 10.12.2010

It is fast and useful, although it consumes much memory


Re: rFile - Faster than y_ini - Kwarde - 10.12.2010

It's nice, if it's faster. I believe your compare / benchmark xD.
Whatever, I have an tip. You made an 'MAX_PLAYERSS'.
You can also undefine MAX_PLAYERS and then define it again! Example:

pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 500 //Max players of your server


- Kevin


Re: rFile - Faster than y_ini - RyDeR` - 10.12.2010

Can you post the benchmark results if you use 500 as MAX_PLAYERS?
If you tested with 50, yes ofcourse it will be faster.