[comp.sys.atari.st.tech] Ptermres

entropy@gnu.ai.mit.edu (entropy) (03/31/91)

If I want a program to malloc() some memory (which I want to stay
around after exiting) can I then do a Ptermres(0, 0) or do I still have
to save the whole program in memory in order to keep that malloc'ed
memory around?  Or should I do Ptermres(256, 0) to keep only the
basepage?  Is it legal to only keep part of the program from the top
to a certain point in the middle?  What is the proper way to calculate
the first parameter for Ptermres to keep the whole thing?  I'm
currently doing Ptermres((base->hitpa - base->lowtpa), 0).

Thanks,
  entropy

csbrod@immd4.informatik.uni-erlangen.de (Claus Brod) (04/02/91)

entropy@gnu.ai.mit.edu (entropy) writes:

>If I want a program to malloc() some memory (which I want to stay
>around after exiting) can I then do a Ptermres(0, 0) or do I still have
>to save the whole program in memory in order to keep that malloc'ed
>memory around?  Or should I do Ptermres(256, 0) to keep only the

When you exit a program via Ptermres() everything you have malloc'ed
stays resident even if you say Ptermres(0,0). If you want to keep
your code resident, too, you'll have to reserve it via Ptermres().
It is legal to keep the start of your program resident and throw
the rest away.
 

----------------------------------------------------------------------
Claus Brod, Am Felsenkeller 2,			Things. Take. Time.
D-8772 Marktheidenfeld, West Germany		(Piet Hein)
csbrod@medusa.informatik.uni-erlangen.de
Claus Brod@wue.maus.de
----------------------------------------------------------------------

wolfram@tschil.informatik.rwth-aachen.de (Wolfram Roesler) (04/08/91)

csbrod@immd4.informatik.uni-erlangen.de (Claus Brod) writes:

>When you exit a program via Ptermres() everything you have malloc'ed
>stays resident even if you say Ptermres(0,0). 

Just to make sure I understood things correctly: So I can write a program that
allocates memory for, say, a cookie jar and then terminates via Ptermres(0,0),
then the program will be removed from memory but the malloced space is ready
to be used by other programs running later?
Is that space EVER freed? 

csbrod@immd4.informatik.uni-erlangen.de (Claus Brod) (04/08/91)

wolfram@tschil.informatik.rwth-aachen.de (Wolfram Roesler) writes:

>Just to make sure I understood things correctly: So I can write a program that
>allocates memory for, say, a cookie jar and then terminates via Ptermres(0,0),
>then the program will be removed from memory but the malloced space is ready
>to be used by other programs running later?
>Is that space EVER freed? 

This space stays resident till MIN(end of time, next cold/warmstart).
Ptermres() hides all memory blocks you allocated, i.e. you won't find
it in any of the two memory lists (memory free list or memory allocated
list). So you can't do Mfree() on it. If I'm wrong here, Allan Pratt
will certainly correct me in an instant 8-)


----------------------------------------------------------------------
Claus Brod, Am Felsenkeller 2,			Things. Take. Time.
D-8772 Marktheidenfeld, West Germany		(Piet Hein)
csbrod@medusa.informatik.uni-erlangen.de
Claus Brod@wue.maus.de
----------------------------------------------------------------------

bjoern@drdhh.hanse.de (Bjoern Kriews) (04/12/91)

From article <1991Apr8.130807.3046@informatik.uni-erlangen.de>, by csbrod@immd4.informatik.uni-erlangen.de (Claus Brod):
> This space stays resident till MIN(end of time, next cold/warmstart).
> Ptermres() hides all memory blocks you allocated, i.e. you won't find
> it in any of the two memory lists (memory free list or memory allocated
> list). So you can't do Mfree() on it. If I'm wrong here, Allan Pratt
> will certainly correct me in an instant 8-)

I'd be glad IF he would - but I think I'm starting to get on his nerves,
so I stop writing... 8-)

bjoern


---
bjoern@drdhh.hanse.de = Bjoern Kriews / Stormsweg 6 / 2000 Hamburg 76 / FRG
"gaaga mahwe Bjoern urgl ufzae Turbo-C bnub"     (J. Willamowius)

apratt@atari.UUCP (Allan Pratt) (04/12/91)

>wolfram@tschil.informatik.rwth-aachen.de (Wolfram Roesler) writes:
>... and then terminates via Ptermres(0,0) ...

csbrod@immd4.informatik.uni-erlangen.de (Claus Brod) writes:
>If I'm wrong here, Allan Pratt
>will certainly correct me in an instant 8-)

Did I hear my name being called?

Ptermres(0,0) is unsafe.  Your TPA is shrunk to zero size (or freed) before
the terminate happens, and therefore you are relying on the contents of
memory that nobody owns: the contents of your basepage to process the
terminate.  This is bad news. Don't do it.  The minimum size argument to
Ptermres should be $80 (the size of your basepage, up to the command line).
This wierd case is not one the authors of GEMDOS (including me)
anticipated, so it's not enforced or anything.  I guess it could be.

Of course, people frequently *do* rely on the contents of memory that
nobody owns, but it's not SAFE.  In particular, that address may have no
meaning any more in a VM system.

============================================
Opinions expressed above do not necessarily	-- Allan Pratt, Atari Corp.
reflect those of Atari Corp. or anyone else.	  ...ames!atari!apratt

csbrod@immd4.informatik.uni-erlangen.de (Claus Brod) (04/13/91)

apratt@atari.UUCP (Allan Pratt) writes:

>Ptermres(0,0) is unsafe.  Your TPA is shrunk to zero size (or freed) before
>the terminate happens, and therefore you are relying on the contents of
>memory that nobody owns: the contents of your basepage to process the
>terminate.  This is bad news. Don't do it.  The minimum size argument to
>Ptermres should be $80 (the size of your basepage, up to the command line).
>This wierd case is not one the authors of GEMDOS (including me)
>anticipated, so it's not enforced or anything.  I guess it could be.

This is what I expected. The discussion, however, was on the question
where malloc'ed blocks go to when you do a Ptermres(0, 0).
To my knowledge, the malloc'ed blocks vanish from both internal
memory lists and so stay resident. I don't see how code packed into
those blocks can crash if it doesn't rely on still being a process
of its own.

Having borrowed your ear 8-), I add a new question: How can one
test reliably if some GEMDOS drive is a BIOS controlled device
or a MetaDOS device?

----------------------------------------------------------------------
Claus Brod, Am Felsenkeller 2,			Things. Take. Time.
D-8772 Marktheidenfeld, West Germany		(Piet Hein)
csbrod@medusa.informatik.uni-erlangen.de
Claus Brod@wue.maus.de
----------------------------------------------------------------------