1. aload

Loads all elements of an array or packed array onto the operand stack.

1.1. Syntax

array aload → array₀ ... arrayₙ₋₁ array
packedarray aload → packedarray₀ ... packedarrayₙ₋₁ packedarray

1.2. Stack Effects

Table 1. Before
Level Object

0

array or packedarray

Table 2. After
Level Object

n

array or packedarray (original)

n-1

array₀ (first element)

…​

…​

0

arrayₙ₋₁ (last element)

1.3. Description

aload successively pushes all n elements of an array or packed array onto the operand stack (where n is the length of the operand), and finally pushes the array or packed array itself back onto the stack.

The elements are pushed in index order: element 0 first, element n-1 last.

1.4. PostScript Level

Level 1 and later (packed arrays in Level 2)

1.5. Examples

Basic array unloading
[23 (ab) -6] aload
% Stack: 23 (ab) -6 [23 (ab) -6]
Processing all elements
[1 2 3 4 5] aload pop  % Pop the array itself
% Stack: 1 2 3 4 5
{ add } repeat          % Sum all values
% Result: 15
Extracting specific elements
[100 200 300] aload
% Stack: 100 200 300 [100 200 300]
pop exch pop
% Stack: 200  (middle element extracted)

1.6. Common Use Cases

1.6.1. Unpacking Coordinate Pairs

/point [ 100 200 ] def
point aload pop moveto  % Unpack and use x, y

1.6.2. Matrix Decomposition

matrix currentmatrix aload pop
% Stack: a b c d tx ty

1.6.3. Processing All Array Elements

[10 20 30] aload pop
% Process each value individually

1.7. Common Pitfalls

Array Remains on Stack - aload leaves the original array on the stack. Use pop if you don’t need it.
[1 2 3] aload    % Stack: 1 2 3 [1 2 3]
% Don't forget the array is still there!
Stack Overflow - Loading large arrays can overflow the operand stack.
1000 array aload  % Might cause stackoverflow
Use with forall - For processing array elements, forall is often more appropriate than aload.

1.8. Error Conditions

Error Condition

[invalidaccess]

Array has no-access attribute

[stackoverflow]

Not enough room on stack for all elements plus array

[stackunderflow]

No operand on stack

[typecheck]

Operand is not an array or packed array

1.9. Implementation Notes

  • Elements are shared between the array and stack (not copied)

  • Modifying a composite element affects both the array and the stack value

  • Works identically for arrays and packed arrays

  • The array reference on top of stack can be used to restore values with astore

1.10. Performance Considerations

  • Loading small arrays is efficient

  • For large arrays, consider using get to access specific elements

  • For iteration, forall is more memory-efficient

1.11. See Also

  • astore - Store stack into array

  • get - Get single array element

  • getinterval - Get subarray

  • forall - Iterate over array elements

  • length - Get array length

  • pop - Remove top stack element


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.