Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #2464 > unrolled thread

save ... restore? setglobal?

Started byjdaw1 <jdawiseman@gmail.com>
First post2016-03-25 09:05 -0700
Last post2016-03-28 12:40 -0700
Articles 12 — 6 participants

Back to article view | Back to comp.lang.postscript


Contents

  save ... restore? setglobal? jdaw1 <jdawiseman@gmail.com> - 2016-03-25 09:05 -0700
    Re: save ... restore? setglobal? luser- -droog <mijoryx@yahoo.com> - 2016-03-25 09:32 -0700
      Re: save ... restore? setglobal? jdaw1 <jdawiseman@gmail.com> - 2016-03-25 10:41 -0700
        Re: save ... restore? setglobal? luser- -droog <mijoryx@yahoo.com> - 2016-03-25 11:16 -0700
          Re: save ... restore? setglobal? jdaw1 <jdawiseman@gmail.com> - 2016-03-25 11:41 -0700
            Re: save ... restore? setglobal? Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-02 02:38 -0700
              Re: save ... restore? setglobal? luser- -droog <mijoryx@yahoo.com> - 2016-06-02 16:08 -0700
          Re: save ... restore? setglobal? Martin Leese <please@see.Web.for.e-mail.INVALID> - 2016-03-26 12:07 -0600
    Re: save ... restore? setglobal? Markus Triska <triska@metalevel.at> - 2016-03-26 09:12 +0100
      Re: save ... restore? setglobal? jdaw1 <jdawiseman@gmail.com> - 2016-03-26 06:37 -0700
        Re: save ... restore? setglobal? Markus Triska <triska@metalevel.at> - 2016-03-27 14:51 +0200
    Re: save ... restore? setglobal? sjprouty3765@gmail.com - 2016-03-28 12:40 -0700

#2464 — save ... restore? setglobal?

Fromjdaw1 <jdawiseman@gmail.com>
Date2016-03-25 09:05 -0700
Subjectsave ... restore? setglobal?
Message-ID<7526030b-9d4c-465e-ab14-eac3ad5b98ef@googlegroups.com>
I maintain a large PostScript program (≈ 12.7k lines). http://www.jdawiseman.com/placemat.html
It does not use save … restore. Indeed, I have never used save … restore in any PostScript program. 

Do you use save … restore? What for? For what should I be using it? 

And yes, I have read §3.7.3, pp61-62, of PLRM3. 

Relatedly, I never use setglobal. Do you use setglobal? What for? For what should I be using it?

[toc] | [next] | [standalone]


#2465

Fromluser- -droog <mijoryx@yahoo.com>
Date2016-03-25 09:32 -0700
Message-ID<a1d28a35-e3fb-4de1-bba5-0ddfc62f323e@googlegroups.com>
In reply to#2464
On Friday, March 25, 2016 at 11:05:17 AM UTC-5, jdaw1 wrote:
> I maintain a large PostScript program (≈ 12.7k lines). http://www.jdawiseman.com/placemat.html
> It does not use save … restore. Indeed, I have never used save … restore in any PostScript program. 
> 
> Do you use save … restore? What for? For what should I be using it? 
> 
> And yes, I have read §3.7.3, pp61-62, of PLRM3. 
> 
> Relatedly, I never use setglobal. Do you use setglobal? What for? For what should I be using it?

`save` and `restore` can be used to bracket sections of
the program which allocates memory that is not needed
after the `restore`. For instance, if you have a "normal"
document (not necessarily DSC-compliant, but roughly laid
out the same) with a prologue section and several distinct
pages, then you can put `save` ... `restore` around each
page description. The memory allocated while executing the
page will be rewound to the same state (mostly).

Since Level 2, postscript has garbage collection, so this
isn't strictly necessary for memory management. But 
judicious use of `save` and `restore` could reduce the
burden on the collector somewhat, with an effect on the
speed of execution.


Also introduced in Level 2 is global memory. This is a 
separate memory space which is not (normally) affected
by `save` and `restore`. You'll only need to use global
memory if you're doing something like defining a resource
or some other special structure which must persist past
the lifetime of any local objects which `restore` might
discard. 

Because local memory is more perishable, there is the
rule that arrays and dicts in global memory cannot contain
references to objects in local memory (because they might
arbitrarily disappear at any time).

tldr; Use `save`...`restore` to rewind the values of all
arrays and dicts to their contents at the time of the `save`.
Use `setglobal` (correctly) if you're trying to use
`defineresource`.

[toc] | [prev] | [next] | [standalone]


#2466

Fromjdaw1 <jdawiseman@gmail.com>
Date2016-03-25 10:41 -0700
Message-ID<0e48a0d4-2166-4007-a78f-d14589651156@googlegroups.com>
In reply to#2465
All fair, and consistent with the manual. But do you actually use it? 

I put temporary arrays inside dictionaries: 1 dict begin /TempArray 99 array def ... end, which should be enough clues for a garbage collector. And if it isn't, well, modern machines have multi-gigabytes of memory, which is enough to last until the final showpage. 

Do you actually use save ... restore?

[toc] | [prev] | [next] | [standalone]


#2467

Fromluser- -droog <mijoryx@yahoo.com>
Date2016-03-25 11:16 -0700
Message-ID<09001fd0-173b-47c7-af85-7da1ba023906@googlegroups.com>
In reply to#2466
On Friday, March 25, 2016 at 12:41:32 PM UTC-5, jdaw1 wrote:
> All fair, and consistent with the manual. But do you actually use it? 
> 
> I put temporary arrays inside dictionaries: 1 dict begin /TempArray 99 array def ... end, which should be enough clues for a garbage collector. And if it isn't, well, modern machines have multi-gigabytes of memory, which is enough to last until the final showpage. 
> 
> Do you actually use save ... restore?

No, not really. Just enough to test my implementation.
My laptop just died, so I can't scan my old files to
see if I've used it for anything weird.

To a degree, it's a legacy from Level 1 where it was the
only way to manage memory.

[toc] | [prev] | [next] | [standalone]


#2468

Fromjdaw1 <jdawiseman@gmail.com>
Date2016-03-25 11:41 -0700
Message-ID<ae1ba1f4-5b84-4e3c-944a-e68733cdda4b@googlegroups.com>
In reply to#2467
Ahh, that is revealing. Thank you. 

If you can't recall using them recently, then I'm not necessarily making an error by not using them.

[toc] | [prev] | [next] | [standalone]


#2604

FromLawrence D’Oliveiro <lawrencedo99@gmail.com>
Date2016-06-02 02:38 -0700
Message-ID<dcf30adc-c93a-4309-9206-12a88c1e5a1a@googlegroups.com>
In reply to#2468
On Saturday, March 26, 2016 at 7:41:21 AM UTC+13, jdaw1 wrote:
> If you can't recall using them recently, then I'm not necessarily making an
> error by not using them.

If you aren’t using save/restore or setglobal, then you’re very probably leaking memory.

Since we can safely assume that every PostScript implementation nowadays has a languagelevel of 2 or greater, I guess the easiest thing to do is to put

    true setglobal

at the start of your program and rely on garbage collection to free up unused memory.

Disclaimer: I haven’t been using them myself either. :)

[toc] | [prev] | [next] | [standalone]


#2609

Fromluser- -droog <mijoryx@yahoo.com>
Date2016-06-02 16:08 -0700
Message-ID<09963787-4149-4cc6-a496-1d5ab103463c@googlegroups.com>
In reply to#2604
On Thursday, June 2, 2016 at 4:38:45 AM UTC-5, Lawrence D’Oliveiro wrote:
> On Saturday, March 26, 2016 at 7:41:21 AM UTC+13, jdaw1 wrote:
> > If you can't recall using them recently, then I'm not necessarily making an
> > error by not using them.
> 
> If you aren’t using save/restore or setglobal, then you’re very probably leaking memory.
> 
> Since we can safely assume that every PostScript implementation nowadays has a languagelevel of 2 or greater, I guess the easiest thing to do is to put
> 
>     true setglobal
> 
> at the start of your program and rely on garbage collection to free up unused memory.
> 
> Disclaimer: I haven’t been using them myself either. :)

Garbage collection applies to local memory as well. So with level 2
and beyond, you don't need to use save and restore for memory 
management. 

It's true that save and restore don't apply to global memory (with
one irrelevant exception: the outermost save/restore in the interpreter
which brackets the entire execution of the system, that save applies
to global memory contents as well). But GC /does/ apply to both.
So `true setglobal` is not needed to take advantage of garbage collection.

[toc] | [prev] | [next] | [standalone]


#2471

FromMartin Leese <please@see.Web.for.e-mail.INVALID>
Date2016-03-26 12:07 -0600
Message-ID<nd6iut$k7v$1@dont-email.me>
In reply to#2467
luser- -droog wrote:

> On Friday, March 25, 2016 at 12:41:32 PM UTC-5, jdaw1 wrote:
...
>> Do you actually use save ... restore?
...
> To a degree, it's a legacy from Level 1 where it was the
> only way to manage memory.

I remember using save/restore extensively,
back in the early 1990s.  However, back
then I had one PostScript Level 1 printer
to support, and so needed to write Level 1
code.  Level 1 printers had limited memory,
so there was an incentive to husband it.

I also used save/restore to restore a
convenient graphics state.  These can take
some trouble to set up, and it can be
useful to easily restore back to it.

Never used setglobal as that is Level 2.
-- 
Regards,
Martin Leese
E-mail: please@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/

[toc] | [prev] | [next] | [standalone]


#2469

FromMarkus Triska <triska@metalevel.at>
Date2016-03-26 09:12 +0100
Message-ID<m21t6xiron.fsf@metalevel.at>
In reply to#2464
jdaw1 <jdawiseman@gmail.com> writes:

> I maintain a large PostScript program (≈ 12.7k lines).
> http://www.jdawiseman.com/placemat.html
> It does not use save … restore. Indeed, I have never used save …
> restore in any PostScript program.
>
> Do you use save … restore? What for? For what should I be using it?

I have written many PostScript programs and, although I am aware of
their existence, have never even once used save and restore. I can
imagine that these operators are useful in certain cases, for example
when you generate documents automatically using different sources.

For other points, I agree with what luser- -droog has written.

Good question, and thank you for persisting!

All the best,
Markus

[toc] | [prev] | [next] | [standalone]


#2470

Fromjdaw1 <jdawiseman@gmail.com>
Date2016-03-26 06:37 -0700
Message-ID<0d7ca416-f156-469d-b0cc-580c6f94b5de@googlegroups.com>
In reply to#2469
> I have ... never even once used save and restore. 

Thank you. So not just me. Is the same true of setglobal?

[toc] | [prev] | [next] | [standalone]


#2472

FromMarkus Triska <triska@metalevel.at>
Date2016-03-27 14:51 +0200
Message-ID<m2wpoogk3m.fsf@metalevel.at>
In reply to#2470
jdaw1 <jdawiseman@gmail.com> writes:

>> I have ... never even once used save and restore. 
>
> Thank you. So not just me. Is the same true of setglobal?

Yes: I have never even once used setglobal despite being aware of it.

All the best,
Markus

[toc] | [prev] | [next] | [standalone]


#2478

Fromsjprouty3765@gmail.com
Date2016-03-28 12:40 -0700
Message-ID<c1038969-008c-44d7-93b8-ca72e5bf3ff0@googlegroups.com>
In reply to#2464
On Friday, March 25, 2016 at 9:05:17 AM UTC-7, jdaw1 wrote:
> I maintain a large PostScript program (≈ 12.7k lines). http://www.jdawiseman.com/placemat.html
> It does not use save … restore. Indeed, I have never used save … restore in any PostScript program. 
> 
> Do you use save … restore? What for? For what should I be using it? 
> 
> And yes, I have read §3.7.3, pp61-62, of PLRM3. 
> 
> Relatedly, I never use setglobal. Do you use setglobal? What for? For what should I be using it?


Well, I have found at least two situations save/restore are useful:

1.  When processing another PostScript or EPS file with "run".  save/restore can protect your code from the code in the external files.

2.  Large number of pages, say 100,000 pages on up (yes, in production print environments even 1 million pages is not unheard of).  save/restore bracketing of each page improves performance greatly and even lets some jobs that would fail with out-of-memory complete.

As for setglobal, if you are not using save/restore then you wouldn't use it.  I use it for situation 2. above where there needs to be some items within a page that carries over to other pages.

Thanks!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web