Question about YSI
#4

Quote:
Originally Posted by Kwarde
View Post
This is the case for all strings (unless if you're using the dynamic memory plugin).
Strings (arrays) are basically just a bunch of variables. PAWN reads these arrays as strings. All string functions (reading strings, strings such as strcmp(), strlen()) use the null terminator (aka EOS aka \0) to find the end of the string.
So if you have the text "hello", the array needs the size of the string (in this case 5) + 1 cell (one cell is one index / memory space of the array) for the null terminator. This is what "hello" would look like:
pawn Code:
//Using: new myArray[] = "Hello";
//Would basically be this:

new myArray[6];
myArray = {
    'H', 'e', 'l', 'l', 'o', EOS //EOS == '\0'
};
If you have a larger array where not all space is used, the null terminator is placed after the last character so that during runtime the end of the string is found. All string functions use the null terminator. Example:
pawn Code:
new myArray[10] = "Hello";
//so, myArray is:
//'H', 'e', 'l', 'l', 'o', EOS, '', '', '', '', EOS
That's why strlen() in this case would return 5 and not 10, because it stops at the null terminator. And as you can see, those unused characters are a waste of space. One cell is 32 bits and thus 4 bytes (1 byte = 8 bits). In above example, 5 cells are wasted and thus 5*4 = 20 bytes.

You don't have to define the array size of the array has a default value/input. For example:
pawn Code:
new myArray[] = "Hello world!";
would automatically assign 13 cells.

And that's why you include one more cell than the size of the array. It is not y_va specific.
Yes my friend thanks for this tutorial is worthing a lot.

This is how i do a format message that i need something to show like a number or a name.
Code:
new string[9], test = 0;
format(string, sizeof(string), "Hello %d", test);
SendClientMessage(playerid, -1, string);
Ok, so i wanted to ask about 'YSI/y_va' if it works how it supposed to be, in that include if you look closely it has something to count the characters then to end it.
The reason why i ask is because i don't need to count every single char, and i don't want to use EOS.

Normal format:
Code:
new string[9], test = 0;
format(string, sizeof(string), "Hello %d", test);
SendClientMessage(playerid, -1, string);
YSI/y_va format:
Code:
new test = 0;
va_SendClientMessage(playerid, -1, "Hello %d", test);
It's more simple and i don't need to count and dont need to use EOS.
And the question about everything is, it is how EOS works to end the character count string at the end or it keeps counting until MAX_STRING and ruin my host CPU MEM ?

Edit: imagine using
Code:
new string[MAX_STRING]; // GLOBAL

new test = 0;
string[0] = (EOS);
format(string, sizeof(string), "Hello %d", test);
SendClientMessage(playerid, -1, string);
Instead of

Code:
new test = 0;
va_SendClientMessage(playerid, -1, "Hello %d", test);
I want to know if 'y_va' will use more CPU MEM than EOS.
Reply


Messages In This Thread
Question about YSI - by MarianImmortalGod - 03.07.2020, 15:09
Re: Question about YSI - by MarianImmortalGod - 03.07.2020, 21:22
Re: Question about YSI - by Kwarde - 04.07.2020, 12:13
Re: Question about YSI - by MarianImmortalGod - 04.07.2020, 12:34
Re: Question about YSI - by Kwarde - 04.07.2020, 21:47
Re: Question about YSI - by MarianImmortalGod - 04.07.2020, 22:19
Re: Question about YSI - by Kwarde - 04.07.2020, 22:54
Re: Question about YSI - by MarianImmortalGod - 04.07.2020, 23:59

Forum Jump:


Users browsing this thread: 2 Guest(s)