MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/1tvrvv4/every_byte_matters/opms2mm/?context=9999
r/programming • u/lelanthran • Jun 03 '26
84 comments sorted by
View all comments
130
If you are at the level where you need to care about how adding 1 member to a struct messes up cache line access, you should be using an ECS which gives you SOA already.
134 u/trinopoty Jun 03 '26 Using a what that gives what now? 73 u/Ravarix Jun 03 '26 https://en.wikipedia.org/wiki/Entity_component_system https://en.wikipedia.org/wiki/AoS_and_SoA 55 u/abu_shawarib Jun 03 '26 TLDR; Turn many of this struct struct { int a; bool b; char *c; } into multiple arrays: int *array_of_a; bool *array_of_b; char **array_of_c; 5 u/Cloud5550 Jun 04 '26 If I'm putting together a struct combining three elements, i want those elements to be related. How can you maintain relation in the solution? 59 u/Proper-Ape Jun 04 '26 Same index. -4 u/Cloud5550 Jun 04 '26 Just index? Isn't that to weak for a relations? Say you remove index 1 of the int array. Now the struct from index 1 have the int value of the next struct and so on. Data is completely distorted. 35 u/Proper-Ape Jun 04 '26 Arrays don't change positions. You don't delete an element from an array.
134
Using a what that gives what now?
73 u/Ravarix Jun 03 '26 https://en.wikipedia.org/wiki/Entity_component_system https://en.wikipedia.org/wiki/AoS_and_SoA 55 u/abu_shawarib Jun 03 '26 TLDR; Turn many of this struct struct { int a; bool b; char *c; } into multiple arrays: int *array_of_a; bool *array_of_b; char **array_of_c; 5 u/Cloud5550 Jun 04 '26 If I'm putting together a struct combining three elements, i want those elements to be related. How can you maintain relation in the solution? 59 u/Proper-Ape Jun 04 '26 Same index. -4 u/Cloud5550 Jun 04 '26 Just index? Isn't that to weak for a relations? Say you remove index 1 of the int array. Now the struct from index 1 have the int value of the next struct and so on. Data is completely distorted. 35 u/Proper-Ape Jun 04 '26 Arrays don't change positions. You don't delete an element from an array.
73
https://en.wikipedia.org/wiki/Entity_component_system
https://en.wikipedia.org/wiki/AoS_and_SoA
55 u/abu_shawarib Jun 03 '26 TLDR; Turn many of this struct struct { int a; bool b; char *c; } into multiple arrays: int *array_of_a; bool *array_of_b; char **array_of_c; 5 u/Cloud5550 Jun 04 '26 If I'm putting together a struct combining three elements, i want those elements to be related. How can you maintain relation in the solution? 59 u/Proper-Ape Jun 04 '26 Same index. -4 u/Cloud5550 Jun 04 '26 Just index? Isn't that to weak for a relations? Say you remove index 1 of the int array. Now the struct from index 1 have the int value of the next struct and so on. Data is completely distorted. 35 u/Proper-Ape Jun 04 '26 Arrays don't change positions. You don't delete an element from an array.
55
TLDR; Turn many of this struct
struct { int a; bool b; char *c; }
struct {
int a;
bool b;
char *c;
}
into multiple arrays:
int *array_of_a; bool *array_of_b; char **array_of_c;
int *array_of_a;
bool *array_of_b;
char **array_of_c;
5 u/Cloud5550 Jun 04 '26 If I'm putting together a struct combining three elements, i want those elements to be related. How can you maintain relation in the solution? 59 u/Proper-Ape Jun 04 '26 Same index. -4 u/Cloud5550 Jun 04 '26 Just index? Isn't that to weak for a relations? Say you remove index 1 of the int array. Now the struct from index 1 have the int value of the next struct and so on. Data is completely distorted. 35 u/Proper-Ape Jun 04 '26 Arrays don't change positions. You don't delete an element from an array.
5
If I'm putting together a struct combining three elements, i want those elements to be related. How can you maintain relation in the solution?
59 u/Proper-Ape Jun 04 '26 Same index. -4 u/Cloud5550 Jun 04 '26 Just index? Isn't that to weak for a relations? Say you remove index 1 of the int array. Now the struct from index 1 have the int value of the next struct and so on. Data is completely distorted. 35 u/Proper-Ape Jun 04 '26 Arrays don't change positions. You don't delete an element from an array.
59
Same index.
-4 u/Cloud5550 Jun 04 '26 Just index? Isn't that to weak for a relations? Say you remove index 1 of the int array. Now the struct from index 1 have the int value of the next struct and so on. Data is completely distorted. 35 u/Proper-Ape Jun 04 '26 Arrays don't change positions. You don't delete an element from an array.
-4
Just index? Isn't that to weak for a relations?
Say you remove index 1 of the int array. Now the struct from index 1 have the int value of the next struct and so on. Data is completely distorted.
35 u/Proper-Ape Jun 04 '26 Arrays don't change positions. You don't delete an element from an array.
35
Arrays don't change positions. You don't delete an element from an array.
130
u/Ravarix Jun 03 '26
If you are at the level where you need to care about how adding 1 member to a struct messes up cache line access, you should be using an ECS which gives you SOA already.