Skip to main content
Participating Frequently
July 6, 2009
Answered

Postscript Stack overflow problem

  • July 6, 2009
  • 1 reply
  • 4515 views

Hi everybody,

I am looking for a detailed information about a

postsript stack functioning,  what commands exactly are put

on the stack and how one can control the stack size

when creating postscript files. We are writing a postscript

driver and our postscripts often shows stack overflow

errors, but we did not find any sufficient information about

how to avoid this problem in neither ps books.

Does a stack size depends on a particular PS interpreter

or are there any standards? What is a typical stack size?

What is the best way for developer to follow the stack size,

so that it does not get overflowed?

Thank you very much in advance for any help,

Yuliana

This topic has been closed for replies.
Correct answer Helge Blischke

I had a look at your sample file. My impression is that puting those huge chunks of

PS code into procedures is not quite adequate. Provided the printers you want to use

are level 3 printers and are equipped with sufficient memory or - even better - a hard

disk, I'd suggest to use the ReusableStreamDecode filter instead as sketched out below:

To set up:

currentfile <</Filter /SubFileDecode /DecodeParms <<0 (%EndOfChunk)>> >> ReusableStreamDecode filter

% your huge chunk of PS code goes here

%EndOfChunk

/name_of_chunk exch def

To use:

name_of_chunk dup resetfile cvx exec

Of course, as Dov posted earlier, the details of storage menagement are highly

implementation dependent, but I think that the reusable stream data are probably

managed aside from the "normal" memory namagement, e.g. saed on a hard disk,

if present, or a ramdisk or the like.

1 reply

Dov Isaacs
Legend
July 6, 2009

The available stack for PostScript is implementation-dependent but is typically sufficient for reasonable PostScript streams. Typically, one might push a few dictionaries on the stack and that shouldn't be a problem. What specifically are you using the stack for when you get such overflows?

          - Dov

- Dov Isaacs, former Adobe Principal Scientist (April 30, 1990 - May 30, 2021)
Participating Frequently
July 7, 2009

I think, our stack problems mostly happen  inside of the procedures, which we use
for repeated code pieces.  I am attaching an example, with the problem inside of the
/f_906_0 procedure. I think, the problem is caused by the repeated font calls before
each text line.  This is definitely not a best way to organize the font calls, but  we can not
always avoid such unefficient programming style, when we converting to postscript from
third party documents.   The problem is typically gone, when we put the same code pieces
direkt into the page descriptions, instead of  calling a procedure. And this is exactly why
I need a detailed information about how one can calculate a stack size - so that I could
estimate the size  needed by a procedure and then decide, whether to use the
procedure or not .
Thank you again for your help,
Yuliana

Participating Frequently
July 7, 2009

It may be your procedures are too large. The following short procedure is fine but if the

1 1 1 1 add add add pop line is repeated 10000 times i gives a stack overflow error. It

did work with 5000 times.

/someproc
{
  1 1 1 1 add add add pop

} def

Starting with /f_894_0 {} cutting out 15000 lines of data out of the large procedures and your file

began showing apges without errors. Either break into smaller ones or look for repeated code to

go into it's onw procedure.

Another option is to increase  your stack e.g.

<<
  /MaxOpStack 10500
>> setuserparams

Ed