You can't implement a linked list without unsafe. Core data structures in std use unsafe and should obviously not link to C code. https://doc.rust-lang.org/src/alloc/collections/linked_list.rs.html#151 …
-
-
I thought there were ways to do it, just not the obvious most efficient ones. If you really *can't*, that makes me a lot more skeptical of the whole Rust model...
1 reply 0 retweets 0 likes -
Yes. You can implement naive linked lists without unsafe.
1 reply 0 retweets 4 likes -
OK. I meant that if the type system Rust bases its memory-safety on didn't admit *any* way to do linked lists without unsafe, the whole formalism would be a lot less impressive/valuable than I thought it was...
2 replies 0 retweets 0 likes -
I didn't even know it was possible, now I want to learn what a linked list looks like without using unsafe
2 replies 0 retweets 2 likes -
Replying to @andy_kelley @RichFelker and
use Rc and Weak Presumably y'all are talking about doubly linked lists, singly linked lists are possible to do efficiently in safe code
4 replies 0 retweets 6 likes -
Replying to @ManishEarth @andy_kelley and
There's also the possibility of using non-pointer references to represent the graph, such as indices into an array or some other pool data structure that holds the nodes
4 replies 0 retweets 8 likes -
Replying to @jckarter @andy_kelley and
Oh yeah, that works too. That's almost as efficient as the unsafe version
2 replies 0 retweets 1 like -
Replying to @ManishEarth @jckarter and
Yeah but there are serious limitations on what you can do with that. I guess you could make all the objects still independent-ish by having an array of refs to them, rather than putting them in an array themselves, but it still adds some disgusting logical "globalness".
1 reply 0 retweets 0 likes -
Replying to @RichFelker @ManishEarth and
Well the other fallacy of LinkedList<T> sorts of types is that you usually want a linked list to be intrusive in T instead of just wrapping a generic value opaquely. So you often already are grooming your element type, and also controlling allocation isn't that much of a stretch
1 reply 0 retweets 1 like
An additional data point: Those of us who do GPU programming are very used to using indices for lists/trees, since the CPU-side address and GPU-side address for a particular block of memory are different, and trying to juggle the two leads to madness :)
-
-
There's a similar problem with sharing data structures between processes using read-only shared memory: if there are pointers and you can't get the same base address, you're out of luck. And by “if” I mean that yes, there are: https://searchfox.org/mozilla-central/source/servo/components/to_shmem/lib.rs …
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.