3 ms·
You could allocate a single novel struct containing the structure of interest and any number of list elements that will contain it in a single malloc(). If the
by robotresearcher 5y ago
You could allocate a single novel struct containing
the structure of interest and any number of list elements that will contain it in a single malloc().
If the lists don’t need to know about each other, each novel struct could be different.
This would work, but it’s a bit exotic, so I’m not recommending it. But it addresses the locality and multiple allocation issues.
- Hello71 5y agoisn't that exactly equivalent to an intrusive linked list in memory except harder to implement?
- adwn 5y agoNot quite. With traditional intrusive linked lists, you'll have to modify the payload struct whenever you want to add it to another or different lists; with OP's approach, maybe not (but it depends on the implementation details).