home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / postscri / 5666 < prev    next >
Encoding:
Text File  |  1992-11-23  |  4.5 KB  |  96 lines

  1. Newsgroups: comp.lang.postscript
  2. Path: sparky!uunet!nntp1.radiomail.net!fernwood!trilithon!henry
  3. From: henry@trilithon.mpk.ca.us (Henry McGilton)
  4. Subject: Re: VM questions in Blue Book
  5. Message-ID: <1992Nov23.055550.18223@trilithon.mpk.ca.us>
  6. Sender: henry@trilithon.mpk.ca.us
  7. Organization: Trilithon Software
  8. References: <1992Nov22.023126.825@eng.ufl.edu>
  9. Date: Mon, 23 Nov 1992 05:55:50 GMT
  10. Lines: 84
  11.  
  12. In article <1992Nov22.023126.825@eng.ufl.edu> zzang@stat.ufl.edu (zzang)  
  13. writes:
  14.     *  I am reading the Blue Book, and I like it very much. but
  15.     *  it is hard for me to understand the virtual memory.  what
  16.     *  is the virtual memory, is it something about the disk spaces
  17.     *  used by the program to extend the RAM capability?
  18.     ``Virtual Memory'' as defined in Adobe books relative to
  19. PostScript, has nothing to do with ``real'' ``virtual memory''
  20. as you would understand using some kind of backing store to provide
  21. the illusion of large amounts of primary memory.
  22.     If you have a disk attached to your printing machine, it does
  23. not contribute towards VM in printer RAM.
  24.     ``Virtual Memory'' as defined in Adobe books refers to a large
  25. amorphous blob of storage where so called ''composite objects''
  26. are allocated.  There's only so much of this blob available, and
  27. when you've used it all up, you're out of luck.  As a PostScript
  28. programmer, you have to manage virtual memory.  When you're writing
  29. one-off trivial PostScript programs, VM is usually no problem.
  30. When you're writing the driver part of an application to generate
  31. pages of PostScript, you have to be aware of what kinds of stuff
  32. use up VM.
  33.     In PostScript Level One, the save and restore mechanisms provide
  34. the means to manage VM.  For document kind of systems, bracketing
  35. each page inside a save and restore pair is a useful notion.  When
  36. you import EPS files, bracket the EPS inside save and restore pairs.
  37.     *  here is the example from the book:
  38.     *  1:
  39.     *  /localdict 1 dict def
  40.     *  /sampleproc {
  41.     *    localdict begin
  42.     *        /localvariable 6 def
  43.     *    end
  44.     *  } def
  45.     This example defines a local dictionary called localdict.
  46. There is only one instance of localdict.  Every time sampleproc
  47. is used, localdict is pushed onto the top of the dictionary stack
  48. (with the begin operator).  A local variable called localvariable
  49. is defined in localdict.  Then localdict is popped off the dictionary
  50. stack (with the end operator).  So far, so good.  localdict consumes
  51. only as much VM as is needed for a dictionary, plus one key/value
  52. pair.  This is all the VM that localdict will consume for the life
  53. of the PostScript job.  localdict was alocated only *once* --
  54. outside the sampleproc procedure.
  55.     *  2:
  56.     *  /sampleproc {
  57.     *    1 dict begin        %this allocates new VM each time
  58.     *        /localvariable 6 def
  59.     *    end
  60.     *  } def        
  61.     This example is subtly different.  *Every Time* sampleproc gets
  62. used, it executes two PostScript instructions (1 dict, and begin)
  63. to allocate a one element dictionary in VM and push that dictionary
  64. onto the top of the dictionary stack.  It then defines a variable
  65. in that dictionary.  Then it pops that dictionary off the dictionary
  66. stack (with the end operator).  As a matter of fact, the definition
  67. of localvariable is irrelevant to this discussion.  What matters
  68. is the allocation of a one element dictionary in VM *every time
  69. sampleproc is used*.  If you do this:
  70.     1 1 100 {
  71.         /MyString (This Is A String) def
  72.     } for
  73. you will end up with 100 (unreferenced) copies of (This Is A String)
  74. in VM.  Even though the contents of the string are the same each time,
  75. a fresh copy of the string is allocated each time through the loop.
  76.     *  The book says the 2nd procedure will use more memory.  but
  77.     *  they look the same to me, I am totally confused.  could
  78.     *  someone explain this.
  79.     A lot of this stuff is explained in our book ``PostScript by
  80. Example'', by Mary Campione and Henry McGilton, published by Addison
  81. Wesley.  At one point in our book we point out the difference
  82. between these two code fragments for working on the font directory:
  83.  
  84.     Code Fragment One                  Code Fragment Two
  85.     ==== ======== ===                  ==== ======== ===
  86. /JunkString 256 string def
  87. FontDirectory {                    FontDirectory {
  88.                                        /JunkString 256 string def
  89.    do a bunch of stuff                 do a bunch of stuff
  90. } forall                           } forall
  91.     Fragment One allocates only one copy of JunkString in VM.
  92. Fragment Two allocates a new copy of JunkString in VM every
  93. time though the loop.
  94.  
  95.     ........  Henry
  96.