Next: 1.6 Dictionaries Up: 1.5 Stacks Previous: 1.5.2 Using the operand Contents Index

## 1.5.3 Efficiency issues

Since stacks are stored internally as doubly linked lists, the cost of indexed access to an object on a stack is proportional to its offset from the top or bottom of the stack, depending on the operator being used. Therefore, stacks are not ideal in situations where arbitrary access to an object is a common operation. An array is a better choice for indexed access, and a dictionary is a better choice for keyed access.

Indexed access doesn't just apply to operators like idup ; operators like nup and roll are also affected. However, operators such as rot are not as heavily impacted, since they only need to index into the stack by the number of positions to rotate.