[comp.sys.amiga.tech] Memory Allocation Question

andrew@bhpese.bhpese.oz (Andrew Steele) (12/02/88)

This is a quick question.
If in a program you have the following statement :

	ptr = AllocMem( 100L , MEMF_FAST );

how will the Amiga handle the case when the is no fast ram left ?

I would think that a lack of fast ram would cause chip ram to be allocated
but I can't find anywhere that explicitly says that this is the case.
				   _____
Andrew Steele 			  /_   _\    Spengat Technologies, 	
			 	  _ | | _    c/o Electrical Computer Services,
ACSnet  : andrew@bhpese.oz	 /__| |__\   BHP Rod & Bar Products Division,
INTERNET: andrew@bhpese.oz.au	             Newcastle, NSW, Australia.
UUCP    : ...!{uunet,mcvax}!munnari!bhpese.oz!andrew

raddison@castor.usc.edu (Richard Addison) (12/03/88)

In <155@bhpese.bhpese.oz> andrew@bhpese.bhpese.oz (Andrew Steele) writes:
>This is a quick question.
>If in a program you have the following statement :
>
>	ptr = AllocMem( 100L , MEMF_FAST );
>
>how will the Amiga handle the case when the is no fast ram left ?
>
>I would think that a lack of fast ram would cause chip ram to be allocated
>but I can't find anywhere that explicitly says that this is the case.

If you ask for MEMF_FAST, you will only get memory that is identified as
FAST; if you ask for MEMF_CHIP, you will only get CHIP memory; if you ask
for MEMF_PUBLIC, you will get PUBLIC memory.

Note that these are not strictly mutually exclusive.  Granted, in the
current system design, CHIP and FAST are distinct, but AllocMem would
operate happily on a MemHeader that is marked both CHIP and FAST.  In
fact, all memory on the Amiga is now marked PUBLIC as well as either
CHIP or FAST.

(Aside:  I sure hope anyone who wants their software to survive any
upgrade to an MMU version of Exec pays strict attention to allocating
shared data objects in PUBLIC memory!)

Now back to what you really want:  Try:

        if (!(ptr = AllocMem(100L,MEMF_FAST)))
          ptr = AllocMem(100L,0L);

So, if there isn't a block of FAST memory that satisfies your request,
you ask for any old block of memory!  Be aware that AllocMem will try
to purge Libraries and Devices that are not currently open before it
returns a NULL pointer.

Richard Addison

(Remember that episode of Gilligan's Island
where they almost got of the island?)

dillon@POSTGRES.BERKELEY.EDU (Matt Dillon) (12/05/88)

:andrew@bhpese.oz.au (Andrew Steele):
:This is a quick question.
:If in a program you have the following statement :
:
:	ptr = AllocMem( 100L , MEMF_FAST );
:
:how will the Amiga handle the case when the is no fast ram left ?

	If you specify MEMF_FAST, and not enough fast memory exists,
NULL will be returned.  Normally, I do this:

	ptr = AllocMem( <blah>, MEMF_PUBLIC);	OR
	ptr = AllocMem( <blah>, 0);		OR

	Here, since you are not specifying any particular type of memory,
the system first checks FAST memory, and if not enough exists it then
tries to allocate from CHIP memory.  It doesn't really matter whether
MEMF_PUBLIC is specified or not (it is unclear when one should specify
it and when one should not, and the current OS does not care).

>I would think that a lack of fast ram would cause chip ram to be allocated
>but I can't find anywhere that explicitly says that this is the case.

	Only if you don't specify a specific type of memory as I did in
my example.


	     .		o
      .	    
     	  			    o
 . 
//					  O

					-Matt\|/
					      *

    "The trajectory failed due to an ill-considered rounding of the 
     floating point quantity by the compiler"

phil@titan.rice.edu (William LeFebvre) (12/10/88)

In article <2077@nunki.usc.edu> raddison@castor.usc.edu (Richard Addison) writes:
>If you ask for MEMF_FAST, you will only get memory that is identified as
>FAST; if you ask for MEMF_CHIP, you will only get CHIP memory; if you ask
>for MEMF_PUBLIC, you will get PUBLIC memory.
>...
>(Aside:  I sure hope anyone who wants their software to survive any
>upgrade to an MMU version of Exec pays strict attention to allocating
>shared data objects in PUBLIC memory!)

The documentation is not particularly clear when something should be
public and when it should not be.  For example, does the string pointed to
by an IntuiText structure need to be public?  My intuition (no pun
intended) says "yes".

It would also be handy if it was easy to pre-declare hunks to be, say,
both chip and public.  "atom" sure won't let you do it!  In fact, it's not
even clear to me if atom's idea of "public" is the same as MEMF_PUBLIC.
The documentation implies (at least to me) that using atom to change
something to "p" just means that it can come out of either chip or fast.
That's not quite the same thing.  I'd like to put all my Intuition
structures (new window and the gadgets especially) in the same hunk and
just delcare that hunk to be public:  I don't want to have to AllocMem all
those suckers.  But, at least in A68K, I'm not sure that I can request
that a given hunk be public.

			William LeFebvre
			Department of Computer Science
			Rice University
			<phil@Rice.edu>