I'm trying to use the list utility that is recommended in Linux kernel. From the introduction in https://isis.poly.edu/kulesh/stuff/src/klist/ one of the feature of the list_head is that the element can belongs to different lists.
Now, if I want a list of all the staff and a list of the old staff only, I think I have to define the following data and structure:
struct list_head all_staff;
struct list_head old_staff;
struct staff {
int age;
struct list_head list; // for all the staff;
struct list_head old;
};
On the other hand, the normal list implementation may be like this:
struct staff {
int age;
};
struct node {
struct node *prev;
struct node *next;
void *element;
};
What's the advantage of list_head compare to the normal list implementation? I feel although the list_head only includes 2 points, removes the point to the element, and so it saves memory, but in this case, I have to add another list_head in the staff structure, if there is only 1 old staff, then it will waste lots of memory.
What's more, if the staff belongs to many different groups, does it mean I have to add many list_head in the staff structure?
Thanks.