

Things you shouldn't do: Two pointers in one field. - RiderOfGiraffes
http://en.wikipedia.org/wiki/XOR_linked_list

======
novas0x2a
Someday you might have to program in an actual resource-constrained
environment, and you'd understand why sometimes you have to do stupid things
to meet your constraints.

Use half the memory -> buy a smaller memory chip per unit -> spend less per
unit -> profit more per unit.

But maybe you should stick with the Ruby. I hear there's money in that.

~~~
jrockway
_Use half the memory - > buy a smaller memory chip per unit -> spend less per
unit -> profit more per unit._

Or: use twice the memory -> buy a bigger memory chip per unit, adding one
dollar to the cost -> charge $1 extra for your $300 unit -> spend less money
defusing "your product sucks because it crashes all the time" support calls ->
profit more per unit.

But maybe you should stick to hand-rolled assembly. I hear there's geek cred
in that.

(But actually, there is a middle ground -- something like Atom:
<http://hackage.haskell.org/package/atom>. You get type safety guarantees at
compile time, and you get a minimal runtime, lowering hardware requirements.)

~~~
xilun666
You seems to think most computers are complicated, with huge amount of memory
needing dedicated and scalable components.

This is not the case. Most computers are tiny; the kind of "you've only got
1kB built-in and non-expandable memory" tiny (yet only if you're lucky). And
most of those computers are indeed programmed correctly, despite using a
number of classical trick like xor linked-lists (the program is small, so
really checking it, even if it contains tricks, is doable).

------
_delirium
Another reason not to do it is that in the modern era, computed pointers tend
to stall pipelines.

~~~
sketerpot
If you're programming for an embedded system with severe memory constraints
and a simple pipeline, this could be worth doing.

------
Groxx
Haha, XOR'd pointers to compress a doubly-linked-list to use a single pointer
for both previous and next references.

Brilliant and deadly. Gotta love it.

------
RiderOfGiraffes
You can build a circular linked-list with this, provided you make "head" a
pair of pointers and adjust your thinking appropriately.

The advantages are real, and not just space efficiency. You can traverse fwd
and bck with identical code, potentially saving code space as well as data
space. Although some other logic is more complicated, you might not need those
other functions.

Don't forget, many embedded processors have moderate ROM and incredibly
restricted RAM. Saving RAM at the expense of ROM can be a sensible trade-off.

------
rmorrison
Let's just hope somebody doesn't try to get sneaky and make a circular XOR
linked list. It'd be hard to start a traversal from head = )

