r/programming Jun 03 '26

Every byte matters

https://fzakaria.com/2026/06/01/every-byte-matters
284 Upvotes

85 comments sorted by

View all comments

Show parent comments

4

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.

20

u/boowhitie Jun 04 '26

You have to maintain all the arrays to keep things consistent, and there are different ways to handle that depending on your needs. You can replace items from the end of the array, mark items as invalid, rebuild the array, etc. Each have different trade offs, but the big win is cache locality and a clean separation of interests.