Integer versus boolean -
BiosMarcel - 14.05.2016
0 and 1 are interpreted as false and true.
so you can basically use an integer as a boolean , since i want to optimize the memory usage i was asking myself what the size of a boolean and the size of an integer is.
I am not sure if it differs from language to language so i am asking here now, please don't answer if you don't know it for sure
Re: Integer versus boolean -
Konstantinos - 14.05.2016
They both have the same size. If you want some optimization, take a look here:
https://sampforum.blast.hk/showthread.php?tid=216730
- "Char-arrays"
- "Bit-flags in enums"
You can also use
rBits or y_bit.
Re: Integer versus boolean -
BiosMarcel - 14.05.2016
so basically boolean is an integer that you can only put 1, 0 , false and true into , but internally it is an integer ? (32 bit value?)
And yeah i am into optiimization, but i still want my code to be clean and readable for everyone
Re: Integer versus boolean -
Konstantinos - 14.05.2016
Yes, Boolean is still 32 bit regardless its tag.
I myself use packed arrays a lot when I know the value of the arrays will not exceed 0-255.
Re: Integer versus boolean -
iggy1 - 14.05.2016
You can also store 32 true/false values in a single variable if you really want to save memory. By using bit flags.
Код:
enum PLAYER_FLAGS :(<<= 1)
{
LOGGED_IN = 1,
IN_RACE
};
new PLAYER_FLAGS: PlayerFlags[MAX_PLAYERS];
//when player logs in...
PlayerFlags[playerid] |= LOGGED_IN;
//when player logs out
PlayerFlags[playerid] &= ~LOGGED_IN;
//check if player is logged in.
if( PlayerFlags[playerid] & LOGGED_IN )
EDIT: Sorry didn't realize that link had already been posted.
Re: Integer versus boolean -
BiosMarcel - 14.05.2016
Quote:
Originally Posted by Konstantinos
|
PHP код:
new bool:test[10 char];
test{0} = false;
test{1} = true;
printf("Char 0: %i",test{0});
printf("Char 1: %i",test{1});
so i have tried that, and this will save up space cause every true(1) and false(0) is stored as a single character?
Re: Integer versus boolean -
Konstantinos - 14.05.2016
Packed arrays are 8 bit.
For 1 bit, use one of the above (rBits or y_bit).
Re: Integer versus boolean -
BiosMarcel - 14.05.2016
I will be using rbits, that seems pretty simple, thanks
Re: Integer versus boolean -
AbyssMorgan - 14.05.2016
Quote:
Originally Posted by [Bios]Marcel
I will be using rbits, that seems pretty simple, thanks
|
Bit Functions is faster:
https://sampforum.blast.hk/showthread.php?tid=591223
Re: Integer versus boolean -
BiosMarcel - 14.05.2016
prove it , but prove it so i can understand it ^^