| ▲ | 10000truths 6 days ago | |||||||||||||||||||
There are a couple other advantages that are unstated in the article, yet very important from a software design perspective: 1) Indices are a lot more portable across different environments than pointers. They can be serialized to disk and/or sent over the network, along with the data structure they refer to. Pointers can't even be shared between different processes, since they're local to an address space by design. 2) Indices enable relocation, but pointers restrict it. A struct that stores a pointer to itself cannot be trivially moved/copied, but a struct containing an integer offset into itself can. A live pointer to an object pool element prevents the object pool from being safely moved around in memory, but an index into the object pool does not impose such restriction. | ||||||||||||||||||||
| ▲ | hinkley 5 days ago | parent | next [-] | |||||||||||||||||||
Someone regaled me with a story of the distributed computing system on the NeXT machines that utilized 64 bit pointers, where the upper bytes were the machine address and the lower bytes the memory address on that machine. | ||||||||||||||||||||
| ▲ | cma 5 days ago | parent | prev | next [-] | |||||||||||||||||||
Data memory-dependent prefetchers like in Apple's newer chips I think only work with full pointers and not offsets, so it could be a decent perf hit. | ||||||||||||||||||||
| ||||||||||||||||||||
| ▲ | vanderZwan 5 days ago | parent | prev [-] | |||||||||||||||||||
The second point is implicitly present in the example given at the end of the "Less Allocation Overhead" section. Copying all nodes from one backing arraylist to a larger one like requires the possibility of relocation. | ||||||||||||||||||||