|
|
|
|
|
by jokoon
4191 days ago
|
|
I don't understand. Is it really well explained ? Aren't ListNode just a way to index a list ? Isn't this Point2D just "marked" to be on a certain list ? Why does he say "less dereferencing" ? > Dereference the appropriate "next" pointer, get the next object from memory. the prev/next pointer is in the ListNode, not in the object itself, so it's obviously a dereference... I did not understand it very well... I can understand that a linked list will be faster thanks to branch prediction, but what does it have to do with an intrusive list ? |
|
The ListNode is embedded in the Point, so their storage is actually combined. The memory layout would be something like
with the total structure being 20 bytes if pointers are 32-bit.> Aren't ListNode just a way to index a list ? Isn't this Point2D just "marked" to be on a certain list ?
The list itself is formed entirely by the ListNodes themselves. There is no backing array to index into; the storage for points (and nodes, which are contained in points) is created with an individual malloc per point. The way you reference a list is by holding a reference to the head, which is just a regular ListNode.