Re:Boehm-Demers-Weiser conservative C/C++ Garbage Collector
by jstimpfle on Sunday January 21, 2024 @12:58PM
(#39080805)
I hope you've stopped laughing and can read and understand my answer.
[ Parent
| on HN ]
Re:Boehm-Demers-Weiser conservative C/C++ Garbage Collector
by groestl on Sunday January 21, 2024 @01:14PM
(#39080998)
Please, I did not want to offend you personally. It just took me by surprise. I understand your points, even though I'm with your direct reply, all things considered.
Re:Boehm-Demers-Weiser conservative C/C++ Garbage Collector
by jstimpfle on Sunday January 21, 2024 @05:35PM
(#39083790)
The address offset subtraction thing specifically is used quite a bit in the Linux kernel for example. It allows to combine abstract code with concrete data. For example they define a red-black tree as a graph of just plain nodes. These nodes are totally abstract, they contain only node pointers but no useful data. The code is totally abstract, no need to instanciate anything a dozen times with different offsets and such. You simply wrap the abstract nodes with whatever concrete useful data you fancy.
The same approach works for lists and a variety of other data structures.
You can get from the abstract link node to the containing struct with a macro: CONTAINER_OF(ptr, containertype, membername). It's easy to use and unlikely to get it wrong.