1. packedarray

Creates a read-only packed array from objects on the stack (Level 2).

1.1. Syntax

any₀ ... anyₙ₋₁ n packedarray → packedarray

1.2. Stack Effects

Table 1. Before
Level Object

n

any₀

…​

…​

1

anyₙ₋₁

0

n (number of elements)

Table 2. After
Level Object

0

packedarray (containing any₀ through anyₙ₋₁)

1.3. Description

packedarray creates a packed array object of length n containing the objects any₀ through anyₙ₋₁ as elements. It:

  1. Removes the integer n from the stack

  2. Removes n objects from the stack

  3. Creates a packed array containing those objects

  4. Pushes the packed array on the stack

The resulting object: * Has type packedarraytype * Has the literal attribute * Has readonly access (cannot be modified) * Is more memory-efficient than regular arrays

The packed array is allocated in local or global VM according to the current VM allocation mode.

1.4. PostScript Level

Level 2 and later

1.5. Examples

Basic packed array
1 2 3 3 packedarray
% Creates read-only packed array
Storing procedures
/add /mul /sub 3 packedarray
% Packed array of operators
Mixed types
42 (text) /name 3 packedarray
% Packed array: <42 (text) /name>

1.6. Common Use Cases

1.6.1. Procedure Definitions

% In Level 2, procedure bodies are packed arrays
true setpacking
{ 1 2 add }  % Creates packed array

1.6.2. Read-Only Data

/constants 1 2 3.14159 3 packedarray def
% Constants cannot be accidentally modified

1.6.3. Memory-Efficient Storage

% Packed arrays use less memory
/data many values here n packedarray def

1.7. Common Pitfalls

Cannot Modify Packed Arrays - Packed arrays are read-only. Attempting to use put or putinterval causes [invalidaccess] error.
1 2 3 3 packedarray
dup 0 99 put  % Error: cannot modify
Global/Local VM Restrictions - If packed array is in global VM and any element is in local VM, [invalidaccess] error occurs.
Use for Procedures - In Level 2, enable packing mode with true setpacking to create packed array procedures automatically.
true setpacking
{ add mul }  % Automatically creates packed array
false setpacking
Read Operations Work Normally - Can use get, getinterval, aload, forall, etc.

1.8. Error Conditions

Error Condition

[invalidaccess]

Packed array in global VM contains local VM objects

[rangecheck]

n is negative or exceeds implementation limit

[stackunderflow]

Fewer than n+1 objects on stack

[typecheck]

Top operand is not an integer

[VMerror]

Insufficient VM to allocate packed array

1.9. Implementation Notes

  • Packed arrays typically use 50-60% less memory than regular arrays

  • Elements are stored more compactly

  • Created with readonly and literal attributes

  • Type is packedarraytype, distinct from arraytype

  • Can be used anywhere regular arrays are accepted (for read operations)

1.10. Comparison with Regular Arrays

Feature Regular Array Packed Array

Memory usage

More

Less (50-60% savings)

Modifiable

Yes

No (readonly)

Access speed

Slightly faster

Slightly slower

Creation

[ …​ ] or array

packedarray or procedures with packing on

Type

arraytype

packedarraytype

1.11. See Also

  • array - Create regular (modifiable) array

  • [ / ] - Array literal syntax

  • aload - Load packed array elements

  • get - Get packed array element

  • forall - Iterate over packed array


Back to top

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