Hello, guys. I today tried to optimize my mine generation system in terms of memory, because it used in 1 minute 1 GB. For this, I tried to switch from Strings to Numbers in bit32 format. I think, that 1 string symbol uses 8 bits, so for simple word like “Stone” it will use 40 bits, and new bit-32 system will use only 8 bits per material.
So, Previously, I used system like this:
Chunk[X][Y][Z] = {
Material = "Stone",
Health = 3,
Tags = {},
}
--[==[
This system, on Z-axis has 16 values
--]==]
And after, I changed this system a lot:
BlockTypes = {
[0b_0000_0000] = "Air",
[0b_0000_0001] = "Stone",
} <-- start of script, to not forget what code is which material
...
...
...
Chunk[X][Y][Z] = {
Material = 0b_0000_0001_0000_0001_0000_0001_0000_0001,
Health = {1, 1, 1, 1},
Tags = {{}, {}, {}, {}},
--[==[
This system, on Z-axis has 4 values, because I use only 8 bits per
material, so if I need get block material, I just "cut" 8 needed bits
from Material, and use them.
Also, because of this material system, I did for Health and Tags array
consisting out of 4 variables.
--]==]
}
But, when playtesting in studio, I received strange result - ABSOLUTELY no diffirence in memory usage! (Only thing improved was speed)
And this leaded me to ask here question - is using bit-32 to write 4 values actually use less memory than Strings?