r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Sep 24 '26
About alignment, struct layout and the cache...
https://meetingcpp.com/blog/items/About-alignment--struct-layout-and-the-cache---.html
36
Upvotes
View all comments
Show parent comment
2
u/pdp10gumby Sep 26 '26
Lists can be as dense as an array, and asymptote towards array size even when manipulated, using CDR-coding, a technique used back in the 70s.
short: instead of having a mode of value and next, you just put the values successively in memory and have a flag (ideally embedded into the value, or even easier, into the value pointer if that’s the representation’s that says, “the next value is at the next location in memory). If you want to splice a new value in or out you have to make two conventional nodes, but depending on your datastructure that may be an uncommon case.
I’ve done this in C++ when I have a free bit available in the range of the content (always true with a pointer these days, but also with, say, an enum).
There’s a crappy Wikipedia page on this topic: https://en.wikipedia.org/wiki/CDR_coding