Memory efficient many-byte variable format

Hi,

I’m creating an experience where players can construct their own map on a 256 x 256 grid. Data is stored in two dimensional arrays in game (one for height, one for color, etc.), to have it readily available. Each value is a one byte variable.

However, when storing player data between sessions, I want to try and use a more memory efficient data type. As I have only one byte values, I can relatively easily just take the approximately 64,000 bytes (256 x 256) and put them into a string variable (with a checksum after each 256). I’m afraid, however, that the string encoding (UTF-8 or whatever) used by Roblox will not be consistant and the data may be destorted.

Can anybody tell me what string encoding Roblox script uses, and if it will be consistant in the future?
Do you have any other ideas for this task?

Thanks a lot.

1 Like

You should consider using buffers instead of strings for your data. That will allow you to read/write arbitrary bytes. Buffers can also be stored in DataStores and Roblox will automatically compress/decompress them for you.

You could also consider techniques like run-length encoding and greedy meshing to further compress your serialization technique while remaining lossless.

1 Like

This seems to be exactly what I was looking for. Will have to do some reading to see if it can really do everything I need, but I think it is the best solution. Haven’t heard of these before, thank you very much.