rust-unofficial / too-many-lists

Learn Rust by writing Entirely Too Many linked lists
https://rust-unofficial.github.io/too-many-lists/
MIT License
3.16k stars 276 forks source link

clarification regarding allocation in `a bad stack` #296

Closed seaerchin closed 5 months ago

seaerchin commented 5 months ago

Problem

[ptr] -> (Elem A, ptr) -> (Elem B, *null*)

In this layout we now unconditionally heap allocate our nodes. The key difference is the absence of the junk from our first layout. What is this junk? To understand that, we'll need to look at how an enum is laid out in memory.

i'm not entirely sure why the node representation for Elem B has a *null*; given that the nodes are required to have a pointer to a List, shouldn't it be (Elem B, ptr) -> (Empty, junk)?

seaerchin commented 5 months ago

closing, realised the author was talking about a potential second layout