Low memory handler

From Amiga Development Wiki
Revision as of 12:21, 30 August 2015 by AmigaDeveloper (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Kickstart 3.0 added AddMemHandler() call to install memory handler to the system. Memory handlers are executed when the system cannot find enough free memory. User applications can use this to free their caches if deemed useful. Here is a short example how to use memory handlers on Amiga.

#include <proto/exec.h>
static ULONG LowMemHandlerCode(REG(A0, struct MemHandlerData *)mhd)
   /* REMEMBER: You are not allowed to break Forbid() */
   if (mhd->memh_Flags & MEMHF_RECYCLE)
      /* free even more memory */
      return MEM_DID_EVERYTHING;
      /* free memory here... */
      return MEM_TRY_AGAIN;
int main()
   struct Interrupt LowMemHandler;
   // Create our memory handler
   LowMemHandler.is_Node.ln_Pri = 50;
   LowMemHandler.is_Node.ln_Name = "Amiga Wiki Example";
   LowMemHandler.is_Data = NULL;
   LowMemHandler.is_Code = (APTR)&LowMemHandlerCode;