[Plugin] JFiles
#1

JFiles
Introduction:
Almost 1 year ago I developed a file system that was called Just_INI which was EXTREMELY low (anyway i just published it in the spanish section) and that also had some issues, now 1 weak ago y got the idea of making this plugin; and here I am.
How does it work?
This plugin handles the files in a completely dynamic way by the use of vectors and maps in C++. The files just exist in the RAM memory of the computer until you convert them in a 'real' file using the cache_MakeRealFile function. This thing of using the files as they were "imaginary" allows you to access the data inside them VERY quickly.

Natives:
Код:
native JINI:cache_CreateFile();
native cache_WriteString(JINI:archivo, key[], val[]);
native cache_WriteInt(JINI:archivo, key[], val);
native cache_WriteFloat(JINI:archivo, key[], Float:val);
native cache_WriteBool(JINI:archivo, key[], bool:val);
native cache_GetString(JINI:archivo, key[], string[], size=sizeof(string));
native cache_GetInt(JINI:archivo, key[]);
native Float:cache_GetFloat(JINI:archivo, key[]);
native bool:cache_GetBool(JINI:archivo, key[]);
native cache_EraseFile(JINI:file);
native cache_MakeRealFile(JINI:JFile, new_file_name[]);
native cache_Clear();
native INI:cache_LoadFileIntoCache(file_name[]);
native cache_RemoveKey(JINI:JFile, key[], typeofkey);
native CreateFolder(folder[]);
native RemoveFolder(folder[]);
native cache_EditString(JINI:archivo, key[], str[]);
native cache_EditInt(JINI:archivo, key[], value);
native cache_EditFloat(JINI:archivo, key[], Float:value);
native cache_EditBool(JINI:archivo, key[], bool:value);
Speed test's:
Test 1:
Код:
[19:54:18] YSI: Write and get 1000 data of a file
[19:54:18] YSI: Took 487 ms.
[19:54:18] JFiles: Took 34 ms.
Test 2:
Код:
[19:54:43] YSI: YSI: Write and get 1000 data of a file
[19:54:44] YSI: Took 713 ms.
[19:54:44] JFiles: Took 36 ms.
Test 3:
Код:
[19:54:52] YSI: Write and get 1000 data of a file
[19:54:53] YSI: Took 719 ms.
[19:54:53] JFiles: Took 35 ms.
The code i did to take the benchmark
pawn Код:
#include <a_samp>

#include <YSI\y_ini>

native JINI:cache_CreateFile();
native cache_WriteString(JINI:archivo, key[], val[]);
native cache_WriteInt(JINI:archivo, key[], val);
native cache_WriteFloat(JINI:archivo, key[], Float:val);
native cache_WriteBool(JINI:archivo, key[], bool:val);
native cache_GetString(JINI:archivo, key[], string[], size=sizeof(string));
native cache_GetInt(JINI:archivo, key[]);
native Float:cache_GetFloat(JINI:archivo, key[]);
native bool:cache_GetBool(JINI:archivo, key[]);
native cache_EraseFile(JINI:file);
native cache_MakeRealFile(JINI:JFile, new_file_name[]);
native cache_Clear();
native INI:cache_LoadFileIntoCache(file_name[]);
native cache_RemoveKey(JINI:JFile, key[], typeofkey);
native CreateFolder(folder[]);
native RemoveFolder(folder[]);
native cache_EditString(JINI:archivo, key[], str[]);
native cache_EditInt(JINI:archivo, key[], value);
native cache_EditFloat(JINI:archivo, key[], Float:value);
native cache_EditBool(JINI:archivo, key[], bool:value);

enum
{
    TYPE_STRING,
    TYPE_INT,
    TYPE_BOOL,
    TYPE_FLOAT
};

public OnGameModeInit()
{
    printf("YSI: Write 1000 data to a file");
   
    new a = GetTickCount();
    new INI:file = INI_Open("archivo.txt");
    for(new i = 0; i < 1000; i++)
    {
        new str[64];
        format(str, sizeof(str), "Number%d", i);
        INI_WriteInt(file,str, i);
        INI_WriteFloat(file, str, 100.0);
    }
    INI_Close(file);
    printf("YSI: Took %d ms.", GetTickCount() - a);
   
    a = GetTickCount();
    new JINI:archivo = cache_CreateFile();
    for(new i = 0; i < 1000; i++)
    {
        new str[64];
        format(str, sizeof(str), "Number%d", i);
        cache_WriteInt(archivo, str, i);
        cache_WriteFloat(archivo, str, 100.0);
    }
    printf("JFiles: Took %d ms.", GetTickCount() - a);
    return 1;
}
Download:
https://www.mediafire.com/?2phwdcderpx1vbi

Credits:
oOFotherOo - Some useful ideas
JustBored - Develop of the plugin.


Documentation:
native cache_CreateFile();
- Creates a new 'file' in the main vector.
Return: This functions returns a handle to the created file.
Use:
pawn Код:
new JINI:archivo = cache_CreateFile();
cache_WriteInt(archivo, "Numero", 1000);
printf("El nъmero que escribi es %d", cache_GetInt(archivo, "Numero"));
//Will print: El nъmero que escribн es 1000
native cache_WriteString(JINI:archivo, key[], val[]);
- Writes a string to the specified file.
Return: It returns true if it wrote fine, otherwise it returns false if a key with the same name already exists.

native cache_WriteInt(JINI:archivo, key[], val);
- Writes a number to the specified file.
Return: It returns true if it wrote fine, otherwise it returns false if a key with the same name already exists.

native cache_WriteFloat(JINI:archivo, key[], Float:val);
- Writes a float number to the specified file.
Return: It returns true if it wrote fine, otherwise it returns false if a key with the same name already exists.

native cache_WriteBool(JINI:archivo, key[], bool:val);
- Writes a boolean value to the specified file.
Return: It returns true if it wrote fine, otherwise it returns false if a key with the same name already exists.

native cache_GetString(JINI:archivo, key[], string[], size=sizeof(string));
- It gets a string of a file that is hold by the correspondient key and passes by reference to the string parameter.
Return: If the file doesnt exists it returns false and no value is passed by reference

native cache_GetInt(JINI:archivo, key[]);

- Gets the value of a int-type key that's inside a file.
Return: Returns the number which was obtain, if the file or the key doesnt exist returns -1.

native Float:cache_GetFloat(JINI:archivo, key[]);

- Gets the value of a float-type key that's inside a file.
Return: Returns the number which was obtain, if the file or the key doesnt exist returns -1.

native bool:cache_GetBool(JINI:archivo, key[]);

- Gets the value of a boolean-type key that's inside a file.
Return: Returns the boolean number which was obtain, if the file or the key doesnt exist returns -1.

native cache_EraseFile(JINI:file);

- Erases the file of the memory and everything that was inside of it.
Return: If the specified file doesnt exist returns 0 otherwise returns 1.

native cache_MakeRealFile(JINI:JFile, new_file_name[]);


- Converts an imaginary file to a real one. The path is specified in the parameter <new_file_name>
Return: If the file does not exist or can not create the new file also returns 0 otherwise returns 1.

native cache_Clear();

- Clean the main vector erasing all data inside, this is mainly if you store too many files in memory and want to clean it not occupy a lot of RAM.

native INI:cache_LoadFileIntoCache(file_name[]);

- Store an actual file in memory so that you can manipulate the other functions of cache.
Return: A handle to the newly created file.

native cache_RemoveKey(JINI:JFile, key[], typeofkey);

- Deletes a "key" of the specified file, the key type must be specified in the typeofkey parameter
The enum that holds the key types.
pawn Код:
enum
{
    TYPE_STRING,
    TYPE_INT,
    TYPE_BOOL,
    TYPE_FLOAT
};
Return: Always returns 1.

native CreateFolder(folder[]);

- Create a new folder in the root folder on the server
Return: Returns 1 in all cases.

native RemoveFolder(folder[]);

- Deletes a folder from the root folder on the server.
Return: Returns 1 in all cases.

native cache_EditString(JINI:archivo, key[], str[]);

- Changes the string value of a key at the specified file.
Return: If the key does not exists returns 0 otherwise returns 1.

native cache_EditInt(JINI:archivo, key[], value);

- Changes the value of a int-type key at the specified file.
Return: If the key does not exists returns 0 otherwise returns 1.

native cache_EditFloat(JINI:archivo, key[], Float:value);

- Changes the value of a float-type key at the specified file.
Return: If the key does not exists returns 0 otherwise returns 1.

native cache_EditBool(JINI:archivo, key[], bool:value);

- Changes the value of a boolean-type key at the specified file.
Return: If the key does not exists returns 0 otherwise returns 1.

I still consider myself a noob in C++ so if you found any bug i would be very grateful; i am not a native speaker so please forgive any grammar mistake.
Reply
#2

Looks good
Would you mind to share the source code with us?
Reply
#3

This is a kind of an issue to compare the usefulness against other, since the data is in the cache and not written, it is useful for in-game data, on the other hand you can store in arrays and not update every action/on every change, but what if I want to access the updated data from other applications ? (PHP, Android app)
Reply
#4

Quote:
Originally Posted by xkirill
Посмотреть сообщение
This is a kind of an issue to compare the usefulness against other, since the data is in the cache and not written, it is useful for in-game data, on the other hand you can store in arrays and not update every action/on every change, but what if I want to access the updated data from other applications ? (PHP, Android app)
Umm, this is very simply done, just save the file often...
Quote:

cache_MakeRealFile(JINI:JFile, new_file_name[]);

Which is the same way you would do it with any other system...





@JustBored: Very nice, but it seems you were kinda trying to start a competition with Y-Less, you should have tried multiple systems... Not only that but try doing each in a different script, I'm not 100% sure there would be a difference but each script should have the same thing just different code...
Reply
#5

Quote:
Originally Posted by Crayder
Посмотреть сообщение
Umm, this is very simply done, just save the file often...


Which is the same way you would do it with any other system...
Oh, I thought he is still talking about functions in C++
Reply
#6

Quote:
Originally Posted by Crayder
Посмотреть сообщение
Umm, this is very simply done, just save the file often...


Which is the same way you would do it with any other system...





@JustBored: Very nice, but it seems you were kinda trying to start a competition with Y-Less, you should have tried multiple systems... Not only that but try doing each in a different script, I'm not 100% sure there would be a difference but each script should have the same thing just different code...
I just compared against y_ini because it's the fastest system so far, so if my code is quicker than y_ini it would be quicker than DINI and other systems. The source code is inside the .rar
Reply
#7

Quote:
Originally Posted by JustBored
Посмотреть сообщение
I just compared against y_ini because it's the fastest system so far, so if my code is quicker than y_ini it would be quicker than DINI and other systems. The source code is inside the .rar
Yes I know that, but it's still like you just called Y-Less out, you could say something like "It's not a competition but... ", it doesn't matter to me though, you still did a great job, I completely understand your viewpoint.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)