3 ms·
2 things concerning wl_list: 1) In C++ you can use struct inheritance to get the same functionality without macros or templates. ie: struct ThingList : wl_lis
by CoolGuySteve 8y ago
2 things concerning wl_list:
1) In C++ you can use struct inheritance to get the same functionality without macros or templates. ie: struct ThingList : wl_list { /* data elements */ }
2) Like in the C++ case above, the next and prev elements should probably be at the top if you plan on iterating a lot since the next/prev pointers will be in the first cacheline that you load when you dereference previous list elem. In this case, it's also worth allocating list nodes with posix_memalign.
OTOH, there might be reasons why you want the list buried deep in the struct, like if the other data element access times are more important.
- ploxiln 8y agoYou can do something similar in C - make struct wl_list the first member of struct data, and just cast the wl_list node pointer to a data pointer (offsetof is zero). I think the most common reason for this generic-location offset-of style is so that the struct data can have multiple list nodes and be on multiple lists (without any extra allocation). This is pretty common in the kernel.
- eps 8y agoRe: #1 - Now try and place Thing on two lists, a map and a hash table or a combination of thereof. No way to do this cleanly in C++. At best, it's going to be an iterator galore, at worst some boost-style frankencode.