![]() |
sponsored links |
|
|
sponsored links
|
|
|
2
9th March 00:03
External User
Posts: 1
|
Thanks to Roger Will****s for his helpful comments. I'm confused by one
point, namely: whereas in reply to my earlier posting about contamination of local variables, I didn't really understand the latter (i.e. the earlier) comment but took it as a caution that using local dictionaries didn't necessarily mean my problem of contamination is "local variables" is thereby solved. That, and Lee Sau Dan's exhortation to write more "native" postscript code by avoiding the use of expensive def's, induced me to eliminate internal def's entirely. That did make it a little harder to write the code at first, but at every stage I was able to make sense of it by writing down what the operand stack had to look like. So, I guess I'm confused as to whether there is something to worry about in using local dictionaries or not and, if so, what is it exactly? Could one give an example showing ********ly what might be wrong with it? If it is really completely safe, it would be much more convenient to use local dictionaries. Ignorantly, Allan Adler ara@zurich.ai.mit.edu ************************************************** ************************** * * * Disclaimer: I am a guest and *not* a member of the MIT Artificial * * Intelligence Lab. My actions and comments do not reflect * * in any way on MIT. Moreover, I am nowhere near the Boston * * metropolitan area. * * * ************************************************** ************************** |
|
|
4
9th March 00:04
External User
Posts: 1
|
One way to avoid the problem is to use structured variable names. For
instance, include the procedure name in each variable. /trapintegrate { /trapintegrate::no_points exch def etc. The :: has no special meaning to PostScript, but it may help to make you confortable with the concepts. This will not help in the case of recursion, of course. ---------------------------------------- Aandi Inston quite@dial.pipex.com http://www.quite.com Please support usenet! Post replies and follow-ups, don't e-mail them. |
|
|
|
5
18th March 07:04
External User
Posts: 1
|
Allan> That, and Lee Sau Dan's exhortation to write more "native"
Allan> postscript code by avoiding the use of expensive def's, Allan> induced me to eliminate internal def's entirely. I'm glad that it worked! ![]() Allan> That did make it a little harder to write the code at Allan> first, but at every stage I was able to make sense of it by Allan> writing down what the operand stack had to look like. Yeah. Have a look at some Postscript code that comes with Fortunately, the authors put comments explaining the stack contents at important points, so that the code isn't that impossible to follow. (And those comments saves me from the need of pulling out a notepad and a pencil to work out what the stack looks like as the routine is run.) Allan> So, I guess I'm confused as to whether there is something Allan> to worry about in using local dictionaries or not and, if Allan> so, what is it exactly? 1) Dictionaries are more expensive. 2) In Postscript Level 1, you have to know precisely the size of your dictionary, or else you get a dictionary overflow (is that the name?). You could avoid that by always OVER-estimating your need. But that translates to: wasting memory. The situation is better in Postscript Level 2 (and later), because dictionaries can grow in size on the fly. e.g. you can simply write "0 dict begin ... def ... def ... end". But bear in mind that growing a dictionary normally takes time linear to the number of existing entries there, plus overhead of reallocating memory. 3) The dictionary stack itself may overflow. I think mose PS interpreters are designed with the assumption that a MUCH larger operand stack is needed than the dictionary stack. So, it's generally more expensive, in terms of space and time, to use local dictionaries. The only thing you get form this is: programming time, esp. if you're not yet fluent in Postscript. Allan> Could one give an example showing ********ly what might be Allan> wrong with it? If it is really completely safe, it would be Allan> much more convenient to use local dictionaries. I don't think so. It depends on whether you speak Postscript fluently or not. I'd find /incr { 1 add } def much more convenient and readable than your /incr { 1 dict begin /x exch def /x x 1 add def x end } def Having said so, I still use local dictionaries in some cases: 1) For write-once-and-dump code. I often hand-edit Postscript files generated by other programs and do something like adjusting the margins, scaling the page, etc. There is no much sense in wasting MY time to optimize such code, which will be dumped once I've got the printout, unless the Postscript Printer is really that handicapped to handle it. 2) For writing the draft versions of some complicated procedures, esp. when the calling interface has not been finalized yet. Using the local-variables approach let's me change the order of operands and add/remove operands in the interface more easily. However, I'd usually start to convert it to the stack-oriented style once the interface is fixed. For _generic_ Postscript procedures, which are meant to be used in a wide range of Postscript files, I always stick to the stack-oriented approach. -- Lee Sau Dan §õ¦u´°(Big5) ~{@nJX6X~}(HZ) E-mail: danlee@informatik.uni-freiburg.de Home page: http://www.informatik.uni-freiburg.de/~danlee |
|
|
6
18th March 07:04
External User
Posts: 1
|
Aandi> One way to avoid the problem is to use structured variable
Aandi> names. For instance, include the procedure name in each Aandi> variable. Aandi> /trapintegrate { /trapintegrate::no_points exch def etc. Aandi> The :: has no special meaning to PostScript, but it may Aandi> help to make you confortable with the concepts. Aandi> This will not help in the case of recursion, of course. Another disadvantage is the higher load exerted on the symbol table (dictionaries) of the Postscript interpreter. -- Lee Sau Dan §õ¦u´°(Big5) ~{@nJX6X~}(HZ) E-mail: danlee@informatik.uni-freiburg.de Home page: http://www.informatik.uni-freiburg.de/~danlee |
|
|
7
18th March 07:04
External User
Posts: 1
|
Higher compared to what? Only to working completely without
variables. As I've often found, this is very expensive in programmer time... ---------------------------------------- Aandi Inston quite@dial.pipex.com http://www.quite.com Please support usenet! Post replies and follow-ups, don't e-mail them. |
|
|
8
18th March 07:04
External User
Posts: 1
|
Aandi> Higher compared to what?
Compared to a more native PS code, which uses a stack oriented approach. Aandi> Only to working completely without variables. As I've often Aandi> found, this is very expensive in programmer time... Yeah. That's a tradeoff. But if you start to "think in Postscript", that won't cost too much time. Somtimes, having to invent variable names for some immediate results gets me stuck (when writing in other languages). Resorting to naming them "i", "j", "k", ... or "v1", "v2", "v3", ... isn't better than thinking in terms of stack contents. -- Lee Sau Dan §õ¦u´°(Big5) ~{@nJX6X~}(HZ) E-mail: danlee@informatik.uni-freiburg.de Home page: http://www.informatik.uni-freiburg.de/~danlee |
|
|
9
18th March 07:05
External User
Posts: 1
|
Can you please recommend some specific files to look at? I'm having trouble
finding what you're referring to in the ghostscript-8.00 distribution. Allan Adler ara@zurich.ai.mit.edu ************************************************** ************************** * * * Disclaimer: I am a guest and *not* a member of the MIT Artificial * * Intelligence Lab. My actions and comments do not reflect * * in any way on MIT. Moreover, I am nowhere near the Boston * * metropolitan area. * * * ************************************************** ************************** |
|
|
10
27th March 09:28
External User
Posts: 1
|
I finally found it in ghostscript-8.00/lib and it is do***ented as Lee Sau Dan
described. Part of my problem in finding it was that I didn't assume that the code was to be found in .ps files and for some reason imagined that there were .c files that contained internal examples of code generation for postscript. Ignorantly, Allan Adler ara@zurich.ai.mit.edu ************************************************** ************************** * * * Disclaimer: I am a guest and *not* a member of the MIT Artificial * * Intelligence Lab. My actions and comments do not reflect * * in any way on MIT. Moreover, I am nowhere near the Boston * * metropolitan area. * * * ************************************************** ************************** |
|