Table memory layout
Posted: Thu Feb 06, 2025 9:44 pm
Hello,
I'm beginning to code my game ECS (I know, how original), and for the way I intend to code it, I have a question about the tables memory layout so as to minimize cache miss occurences.
I have read a bit about table memory layout, but It's difficult to understand for my tiny brain, so please bear with me.
If I get it correctly, tables have two distinct part, an array-like part, and a hash-map part, depending on what data is stored inside them ( = how we use them, pure array or associative array), and for the first part, array, memory should be contiguous right ? But the second part, the hash map, is not.
So, what about a table like so :
Since the values are arrays, is the memory of each of these arrays contiguous as well ? I'm not asking if array_2 is contiguous to array_1, that I guess it is not. But {2, 3, 5, 6, 8, 9} should be, as well as {6, 13, 25, 96, 78, 49}....right ?
Thank you for the help, sorry for my english.
EDIT : btw, I have read these topics, and found bits of info.
viewtopic.php?t=82902
viewtopic.php?t=86843
viewtopic.php?t=84361
I will not use ffi ; the GBC can fragment initially contiguous memory ? If I remove 25, will it still be contiguous then ?
I'm beginning to code my game ECS (I know, how original), and for the way I intend to code it, I have a question about the tables memory layout so as to minimize cache miss occurences.
I have read a bit about table memory layout, but It's difficult to understand for my tiny brain, so please bear with me.
If I get it correctly, tables have two distinct part, an array-like part, and a hash-map part, depending on what data is stored inside them ( = how we use them, pure array or associative array), and for the first part, array, memory should be contiguous right ? But the second part, the hash map, is not.
So, what about a table like so :
Code: Select all
mytable[array_1] = {2, 3, 5, 6, 8, 9}
mytable[array_2] = {6, 13, 25, 96, 78, 49}
Thank you for the help, sorry for my english.
EDIT : btw, I have read these topics, and found bits of info.
viewtopic.php?t=82902
viewtopic.php?t=86843
viewtopic.php?t=84361
I will not use ffi ; the GBC can fragment initially contiguous memory ? If I remove 25, will it still be contiguous then ?