Memory allocation efficiency

GoonyGuy

New Member
Oct 13, 2022
2
2
25
Not wanting to tell people how to write their code, + also completely possible the wiki is wrong since I doubt the save editing part of the wiki has been updated recently, but at least from my end I think there are spots that it might make more sense to use a byte data type instead of integer to save memory. Given the game itself has a very low memory impact, but for certain mobile devices it might more more sense to allocate less memory to variables that won't exceed 5 for instance. Additionally if a byte variable would have to be used with an integer, it could just be type cast, or depending on the situation might just cast itself to an integer implicitly. Kind of an odd comment, but I was dissecting one of my favorite games cause I'm a nerd and happened to notice this.
 

Skunkupine

Well-Known Member
Jun 17, 2023
377
118
Not wanting to tell people how to write their code, + also completely possible the wiki is wrong since I doubt the save editing part of the wiki has been updated recently, but at least from my end I think there are spots that it might make more sense to use a byte data type instead of integer to save memory. Given the game itself has a very low memory impact, but for certain mobile devices it might more more sense to allocate less memory to variables that won't exceed 5 for instance. Additionally if a byte variable would have to be used with an integer, it could just be type cast, or depending on the situation might just cast itself to an integer implicitly. Kind of an odd comment, but I was dissecting one of my favorite games cause I'm a nerd and happened to notice this.
Unfortunately, Javascript doesn't really have a very rich set of data types - pretty much it has the idea of "a number", not ::std::uint8_t, ::std::uint16_t etc.
 

Gedan

BUTTS BUTTS BUTTS
Staff member
Aug 26, 2015
8,008,986
8,008,332
Technically it has typed arrays, but I don't think trying to build some kind of bit-masked memorypool of stuff shoved into uint64 arrays is worth the effort.
 

Skunkupine

Well-Known Member
Jun 17, 2023
377
118
Technically it has typed arrays, but I don't think trying to build some kind of bit-masked memorypool of stuff shoved into uint64 arrays is worth the effort.
Yes, you end up spending more memory on the code to frob the arrays than you are likely going to save on the data. And then all the bugs that introduces, and all the time wasted hand coding.