1. dict

Creates a new empty dictionary with specified initial capacity.

1.1. Syntax

int dict → dict

1.2. Stack Effects

Table 1. Before
Level Object

0

int (non-negative integer)

Table 2. After
Level Object

0

dict (new empty dictionary)

1.3. Description

dict creates an empty dictionary with an initial capacity of int elements and pushes it onto the operand stack.

Level 1: The dictionary has a fixed maximum capacity of int elements. Attempting to exceed this causes [dictfull] error.

Level 2: The int operand specifies only the initial capacity; the dictionary can grow automatically beyond that if needed.

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

1.4. PostScript Level

Level 1 and later

1.5. Examples

Basic dictionary creation
5 dict  % Create dictionary with capacity for 5 entries
Create and populate
10 dict begin
  /name (PostScript) def
  /version 2 def
  /active true def
end
Dictionary for configuration
/config 20 dict def
config /fontSize 12 put
config /fontName /Helvetica put

1.6. Common Use Cases

1.6.1. Local Variable Scope

/myFunction {
  5 dict begin
    /localVar1 10 def
    /localVar2 20 def
    % Use local variables
    localVar1 localVar2 add
  end
} def

1.6.2. Configuration Storage

/settings 50 dict def
settings begin
  /margin 72 def
  /pageWidth 612 def
  /pageHeight 792 def
end

1.7. Common Pitfalls

Size Matters in Level 1 - In Level 1, choose int large enough for all entries. Exceeding capacity causes [dictfull].
% Level 1
2 dict begin
  /key1 1 def
  /key2 2 def
  /key3 3 def  % Error: dictfull
end
Growing Costs in Level 2 - Even in Level 2, growing a dictionary consumes additional VM and has performance costs.
Choose Appropriate Size - Estimate needed size to avoid expensive expansion: * Small dictionaries: 5-10 entries * Medium dictionaries: 20-50 entries * Large dictionaries: 100+ entries

1.8. Error Conditions

Error Condition

[limitcheck]

int exceeds implementation limits

[stackunderflow]

No operand on stack

[typecheck]

Operand is not an integer

[VMerror]

Insufficient VM to allocate dictionary

1.9. Implementation Notes

Level 1: * Fixed capacity set at creation * Cannot exceed int entries * Simple hash table implementation

Level 2: * Initial capacity of int * Auto-expands when needed * Expansion in chunks for efficiency * May contain unused space after expansion

1.10. Performance Considerations

  • Choose initial size wisely to avoid expansion

  • Expansion is expensive (rehashing required)

  • Small initial size OK if final size unknown

  • Large initial size wastes VM if unused

1.11. Standard Dictionaries

Dictionary Purpose

systemdict

Read-only system operators and definitions

globaldict

Global definitions (Level 2)

userdict

User definitions (writable)

errordict

Error handling procedures

$error

Error state information

statusdict

Product-specific information

1.12. See Also

  • begin - Push dict onto dict stack

  • end - Pop dict from dict stack

  • def - Define entry in current dict

  • maxlength - Get maximum capacity

  • length - Get current entry count


Back to top

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