Skip to content

Comment on Intrusive linked lists (2019)parent

Comments

If I do address math on the pointer in order to find a payload, then isn’t the payload tied into exactly one next pointer, and thus exactly one list?

The container_of macro takes the type and member - so for a different member it can subtract a different offset.

Going more basic, you could imagine creating something like:

    struct Node {
        Node* next;
        Node* next_10th;
        Node* next_100th;
    };
The normal, 10ths, and 100ths lists are distinct collections, this is the basic idea. The macros just help generalise it and make it more usable.

Ah yes if all collections are explicitly listed in the list node type, that makes sense. I thought the suggestion was that you could somehow link any given payload entry into multiple independent lists each with their own list node type.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.