beautypg.com

Packed arrays, Packed arrays versus ordinary arrays, Creating packed arrays – Apple LaserWriter Select 310 Printer User Manual

Page 52: Packed arrays 2

background image

C H A P T E R 2

LaserWriter Select 310 Software

40

PostScript Language Changes

Packed Arrays

2

PostScript language procedures are represented as executable arrays, which were
previously stored in the same fashion as literal data arrays. This type of representation
offers maximum flexibility but is very costly in terms of space, requiring 8 bytes per
element. Large PostScript Language programs, such as the built-in server program, and
downloaded preambles, consume considerable amounts of virtual memory.

Programs do not require the ability to be treated as data, but only the ability to be
executed. The packed array fulfils this requirement. Programs represented as packed
arrays are typically 50% to 70% smaller than programs represented as ordinary arrays.

Packed Arrays Versus Ordinary Arrays

2

The packed array object has a type different from an ordinary array, using
packedarraytype

instead of arraytype. However, in most respects it behaves

in the same way. You can

extract elements using get

extract subarrays using getinterval

enumerate the array using forall

Individual elements extracted from a packed array are ordinary PostScript language
objects. A sub-array of a packed array is also a packed array.

Packed arrays are different from ordinary arrays in the following ways:

packed arrays are always read only; you cannot use put or putinterval to store
into one

packed arrays are created differently; (see the section below, “Creating Packed Arrays”)

accessing arbitrary elements of a packed array can be quite a slow process; however,
accessing elements sequentially, as the PostScript interpreter and the forall operator
do, is almost as efficient as accessing an ordinary array

the copy operator cannot copy into a packed array, since the array is read only.
However, it can copy the value of a packed array to an ordinary array that is at least as
long as the packed array

Creating Packed Arrays

2

Packed arrays may be created in two ways. The first and more common way is for the
PostScript interpreter’s input scanner to create packed arrays automatically for all
executable arrays that it reads. This means that whenever the scanner encounters a {
while reading a file or string, it accumulates all tokens up to the matching } and turns
them into a packed array instead of an ordinary array.

The choice of array type is controlled by a mode setting, manipulated by the new
operators, setpacking and currentpacking. (See “Setting Extensions to PostScript
Level 1,” earlier in this chapter.) If the array packing mode is true, PostScript language
procedures encountered subsequently by the scanner are created as packed arrays. If the
mode is false, procedures are created as ordinary arrays. The default value is false
to preserve compatibility with existing programs.