[comp.sys.amiga] Low Memory Server From ASDG

perry@well.UUCP (06/11/87)

As part of the development of FacII - I have written a general purpose
low-memory ``server.'' That is,  an  agent  which will allow arbitrary
processes to register  with  it  their  desire to be notified when the
system is low on memory (actually - whenever an AllocMem fails).

The actual implementation is as a shared library (about 1K) which con-
tains two library calls. These are:

	RegLowMemReq - Register Low Memory Request

	res = RegLowMemReq(PortName , LowMemMsgPtr);
	d0                    a0           a1

	DeRegLowMemReq - Deregister Low Memory Request

	(void) DeRegLowMemReq(PortName);
				 a0

Below is the include file you would use to program with the low-memory
server.  It contains  the conditions under which we are releasing this
software for public redistribution (we retain all rights and allow re-
distribution for non-commercial  purposes  only - commercial redistri-
is granted by licensing agreement whcih says simply that you'll credit
us  somewhere  in  your  documentation and will send us a copy of your
product).

The low-memory server library  is  written completely in assembly lan-
guage and is  quite  small and efficient. It will properly expunge it-
self upon receiving its last closelibrary.

It will accomodate an arbitrarily large  number  of  clients  and will
perform consistency checks  before  actually sending a message to help
prevent the possibility of a message being sent to nowhere.

In the next  few days I will post the library itself, full programming
examples, and full programming documentation.

And by the way - FaccII is coming along VERY well. Many of the comments
made here on usenet have been incorporated into the product.

Cheers, 

Perry S. Kivolowitz - ASDG Incorporated - (201) 563-0529

-----cut here----

/*
**	:ts=8
**
**	low-mem.h
**
**	Copyright 1987 By ASDG Incorporated - All Rights Reserved
**	May  be  freely redistributed for non-commercial purposes 
**	provided this  message  retains intact. Available for use
**	in commercial  products for VERY minimal concession. Con-
**	tact ASDG Incorporated at  (201) 563-0529. Use in commer-
**	cial products without  authorization of ASDG Incorporated
**	shall be viewed as copyright infringement and piracy.
**
**	For commercial applications of the low-memory server ASDG
**	will grant perpetual use licenses provided that:
**		a) We are credited  somewhere  in your documenta-
**		   tion.
**		b) You send us a copy of the application.
**		c) You pay a  very small  administrative fee  not
**		   exceeding $50 if we find it necessary.
**
**	Author:	Perry S. Kivolowitz
*/

/*
**	To use the low-memory server you must allocate one of these
**	structures.  When a  low memory  condition exists, the low-
**	memory server will look for  the message port you specified
**	in the call to RegLowMemReq.  If the message port is found,
**	the low-memory  server will  examine the LoeMemMsg you sup-
**	plied a pointer to in the call to RegLowMemReq.
**
**	If the low-memory server finds something other than LM_CON-
**	DITION_ACKNOWLEDGED, it will not send you a message. There-
**	fore you should initialize this field with that value.
**
**	This scheme  is  used to  ensure that the low-memory server
**	does not reuse the same LowMemMsg (which you supply).  This
**	scheme allows the low-memory server to not wait for a Reply
**	which could be deadly if none was forthcoming from your ap-
**	plication.
*/

struct LowMemMsg {
	struct Message lm_msg;
	long lm_flag;
};


/*
**	values for lm_flag
*/

#define	LM_LOW_MEMORY_CONDITION		0x00000000
#define	LM_CONDITION_ACKNOWLEDGED	(('A'<<24)|('S'<<16)|('D'<<8)|'G')

/*
**	useful defines as in:
**
**	lmptr = (LMPtr) AllocMem(SizeOfLMMsg , 0L);
*/

#define	SizeOfLMMsg	sizeof(struct LowMemMsg)
#define	LMMPtr		struct LowMemMsg *

/*
**	Meaning of Error Returns coming back from RegLowMemReq
*/

#define	LM_BADNAME	-1	/* duplication of port name */
#define	LM_NOMEM	-2	/* memory allocation failed */

bryce@COGSCI.BERKELEY.EDU (Bryce Nesbitt) (06/12/87)

> As part of the development of FacII - I have written a general purpose
> low-memory ``server.'' That is,  an  agent  which will allow arbitrary
> processes to register  with  it  their  desire to be notified when the
> system is low on memory (actually - whenever an AllocMem fails).

!!!PLEASE include a priority!!!  Some users of this function will want to dump
their memory at the earliest hint of need.  Others will want to be stingy
and hang on until there is no alternative. 

With the distibution list suggested priorities for different things.  Not
an exact science, but a guide at least.

!!!PLEASE!!!
----------------------------
Also, if possible, pass the ammount of memory needed.
----------------------------

FaccIII ideas:

2> If it is not already planned, give the control window the ability to
   "disappear".  Not just hide, but go away completly.  Sort of like a TSR,
   terminate and stay resident.  If the user wanted the window again they
   could crank up the icon and FaccIII would be smart enough to
   link up the the public port it left last time.

1> When a large file is loaded in as a chunk it is unlikely that it will be
   accessed again soon.  Think about a large binary like an assembler, text
   editor or "DeluxeMusic".  Any buffers used to hold these are almost
   completly wasted.

   The exception here is the portions of the file used for overlays and the
   blocks of type "T.LIST".  Blocks of type "T.SHORT" are also of a much
   higher priority than simple data blocks of a large file.

   I realize that this gets into mucking with the structure of a disk of type
   "DOS ". 
   -> This would only be acceptable if you checked the type of disk
   you are buffering and fell back to the old way on types like "FDOS" or
   "DOS2". <-

Have an nice day!