04.02.2016, 17:01
(
Последний раз редактировалось MakuPL; 06.02.2016 в 19:55.
)
Name: mBits
Version: 1.2
Author: Maku
Description:
Small include for beginners. It saves memory by using binary numbers.
Boolean, which occupy memory as much as an ordinary variable. Boolean can be replaced by binary numbers, which allows you to save 31 true / false on one variable. In short, what gives us the use of this include?
Instead of this:
We have this:
Functions:
1. Create:
2. Check value of bit. Return: true or false
3. Switch value of bit (if we had true, then we have a false and vice versa). Return: always "1"
4. Set value of bit (true)
5. Set value of bit (false)
Defines:
Informations:
1. Parameter "bit" is the simplest words "slot save." So like a "new bool:Info[100];" = 100 slots. This parameter should be one of the definitions above (unless someone knows the power of two to 31)
2. Use the "bit" values other than the definitions of "BIT_VAR_x" will lead to errors in reading the value or overwriting.
3. Created a variable for the bit values can also be treated as an ordinary integer and saving it to a MySQL database or files, making it easy to read and save the player settings.
4. Include You can also replace with the macro-definitions gaining maximum optimization, but for beginners I recommend stocks what I created.
5. Limit the stored values for each variable is 31, because one variable is 32 bits (32 bit shift the stored number to a negative).
Download:
v1.2 - http://pastebin.com/VutW630D
Test script - http://pastebin.com/MjK1LgEj
Thanks for Yahas.
mBits is faster than BitFunctions by Abyss Morgan and rBits by RyDeR`. Compared to booleans is almost identical (small difference and depends on the situation. Once faster, once slower (max 200ms difference at 1milion execution)). mBits uses less memory than booleans (32 times less).
Version: 1.2
Author: Maku
Description:
Small include for beginners. It saves memory by using binary numbers.
Boolean, which occupy memory as much as an ordinary variable. Boolean can be replaced by binary numbers, which allows you to save 31 true / false on one variable. In short, what gives us the use of this include?
Instead of this:
Код:
new bool:PlayerAdmin[MAX_PLAYERS]; new bool:Nitro[MAX_PLAYERS]; new bool:Mute[MAX_PLAYERS]; new bool:InFun[MAX_PLAYERS]; new bool:VIP[MAX_PLAYERS];
Код:
new playerBit[MAX_PLAYERS];
1. Create:
Код:
new variable;
Код:
IsBit(var, bit)
Код:
SwitchBit(var, bit)
Код:
SetBitTrue(var, bit)
Код:
SetBitFalse(var, bit)
Код:
#define BIT_VAR_1 (1) #define BIT_VAR_2 (2) #define BIT_VAR_3 (4) #define BIT_VAR_4 (8) #define BIT_VAR_5 (16) #define BIT_VAR_6 (32) #define BIT_VAR_7 (64) #define BIT_VAR_8 (128) #define BIT_VAR_9 (256) #define BIT_VAR_10 (512) #define BIT_VAR_11 (1024) #define BIT_VAR_12 (2048) #define BIT_VAR_13 (4096) #define BIT_VAR_14 (8192) #define BIT_VAR_15 (16384) #define BIT_VAR_16 (32768) #define BIT_VAR_17 (65536) #define BIT_VAR_18 (131072) #define BIT_VAR_19 (262144) #define BIT_VAR_20 (524288) #define BIT_VAR_21 (1048576) #define BIT_VAR_22 (2097152) #define BIT_VAR_23 (4194304) #define BIT_VAR_24 (8388608) #define BIT_VAR_25 (16777216) #define BIT_VAR_26 (33554432) #define BIT_VAR_27 (67108864) #define BIT_VAR_28 (134217728) #define BIT_VAR_29 (268435456) #define BIT_VAR_30 (536870912) #define BIT_VAR_31 (1073741824)
1. Parameter "bit" is the simplest words "slot save." So like a "new bool:Info[100];" = 100 slots. This parameter should be one of the definitions above (unless someone knows the power of two to 31)
2. Use the "bit" values other than the definitions of "BIT_VAR_x" will lead to errors in reading the value or overwriting.
3. Created a variable for the bit values can also be treated as an ordinary integer and saving it to a MySQL database or files, making it easy to read and save the player settings.
4. Include You can also replace with the macro-definitions gaining maximum optimization, but for beginners I recommend stocks what I created.
5. Limit the stored values for each variable is 31, because one variable is 32 bits (32 bit shift the stored number to a negative).
Download:
v1.2 - http://pastebin.com/VutW630D
Test script - http://pastebin.com/MjK1LgEj
Thanks for Yahas.
Код:
BitFunctions: 1707ms mBits: 475ms rBits: 6926ms Booleans: 524ms Filterscript 'fastbits.amx' loaded. reloadfs fastbits Filterscript 'fastbits.amx' unloaded. BitFunctions: 1762ms mBits: 475ms rBits: 7106ms Booleans: 532ms Filterscript 'fastbits.amx' loaded.