Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Reid G.C.Thinking in PostScript.1990.pdf
Скачиваний:
17
Добавлен:
23.08.2013
Размер:
846.44 Кб
Скачать

GLOBAL DICTIONARIES OF PROCEDURES

 

The only time you really need local dictionaries is for re-entrant code or

 

recursion. For most other situations, a good approach is to create one

 

larger dictionary to hold both procedures and their data, as long as you are

 

careful about name conflicts (Example 10.3). They are not really “local

 

variables,” but if you need to be careful about storage space but are not

 

worried about recursion or name conflict within your own code, this is

 

much simpler and more efficient. This technique also relieves each

 

procedure of having to begin and end the dictionary, which makes it

 

easier to maintain and faster at the same time.

 

 

 

 

TIP

Most PostScript drivers and any program with more than a small handful

 

of procedures should make sure to build its own dictionary for storing the

 

procedures, to avoid the dictfull error that might result if you trust the exe-

 

cution environment to have enough room in, say, the userdict dictionary

 

for all your definitions.

 

 

 

 

 

 

Example 10.3 shows the use of a single dictionary for all definitions made

 

by the program. This technique can be a little bit riskier, since there is still

 

a chance that another dictionary might be left on top of ProductDict

 

(perhaps by an included illustration); this would make all subsequent

 

instances of def write into the wrong dictionary. However, you can make

 

sure to check the dictionary stack whenever you include an illustration.

 

This technique is the best general approach for storing definitions in a

 

private dictionary.

 

 

Example 10.4: All Procedures within One Global Dictionary

 

/ProductDict 7 dict def

 

 

ProductDict begin

 

 

/Text

% (string) Xloc Yloc Text -

 

{ %def

 

 

/X exch def

 

 

/Y exch def

 

 

/text exch def

 

X Y moveto text show

} bind def

Chapter 10: USING DICTIONARIES

123