Posts: 1,219
Threads: 51
Joined: Jul 2012
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
Posts: 1,219
Threads: 51
Joined: Jul 2012
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
Posts: 11,827
Threads: 33
Joined: Dec 2011
Reputation:
0
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.
Posts: 1,219
Threads: 51
Joined: Jul 2012
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?
Posts: 11,827
Threads: 33
Joined: Dec 2011
Reputation:
0
Packed arrays are 8 bit.
For 1 bit, use one of the above (rBits or y_bit).
Posts: 1,219
Threads: 51
Joined: Jul 2012
I will be using rbits, that seems pretty simple, thanks
Posts: 1,208
Threads: 36
Joined: Apr 2015
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
Posts: 1,219
Threads: 51
Joined: Jul 2012
prove it , but prove it so i can understand it ^^