#ifndef __INC_POS_PEXEC_MEMORY_H
#define __INC_POS_PEXEC_MEMORY_H
/*******************************************************************
 Includes Release 24
 (C) Copyright 1995-1997 proDAD
     All Rights Reserved

 $AUT Holger Burkarth
 $DAT >>Memory.h<<   24 Mar 1997    10:10:33 - (C) ProDAD
*******************************************************************/
#ifndef __INC_POS_PEXEC_LIST_H
#include <pExec/List.h>
#endif
 #ifndef __INC_POS_PEXEC_EXECBASE_H
 #include <pExec/ExecBase.h>
 #endif


/*----------------------------------
-----------------------------------*/
struct pOS_MemChunk
{
  struct pOS_MemChunk *mc_Next;  /* pointer to next chunk */
  size_t               mc_Bytes;  /* chunk byte size */
};



/*----------------------------------
-----------------------------------*/
struct pOS_MemHeader
{
  struct pOS_ExNode    mh_Node;
  UWORD                mh_Attributes;      /* characteristics of this region */
  struct pOS_MemChunk *mh_First;          /* first free region            */
  APTR                 mh_Lower;           /* lower memory bound           */
  APTR                 mh_Upper;           /* upper memory bound+1 */
  size_t               mh_Free;            /* total number of free bytes   */

  UBYTE mh_Reserved[16];
};



/*----------------------------------
-----------------------------------*/
struct pOS_MemEntry
{
  union {
    ULONG   meu_Reqs;   /* the AllocMem requirements */
    APTR    meu_Addr;   /* the address of this memory region */
  } me_Un;
  size_t   me_Length;   /* the length of this memory region */

#define me_Addr  me_Un.meu_Addr
#define me_Reqs  me_Un.meu_Reqs
};




/* Note: sizeof(struct MemList) includes the size of the first MemEntry! */
/*----------------------------------
-----------------------------------*/
struct pOS_MemList
{
  struct pOS_ExNode   ml_Node;
  UWORD               ml_NumEntries;  /* number of entries in this struct */
  struct pOS_MemEntry ml_ME[1];       /* the first entry      */
};




/*----------------------------------
-----------------------------------*/
struct pOS_MemPool
{
  struct pOS_ExList mpl_List;      /* Liste der pOS_MemHeaders */
  size_t            mpl_SegmSize;  /* standard-size eines Segmentes */
  ULONG             mpl_SegmFlags; /* Alloc-Flags (enum pOS_MemoryFlag) */

  __ARID__ struct pOS_MemHeader* (*mpl_Alloc)(_R_LB struct pOS_ExecBase*,_R_A0 struct pOS_MemPool*,_R_D0 size_t);
  VOID                           (*mpl_Free)(_R_LB struct pOS_ExecBase*,_R_A0 struct pOS_MemPool*,_R_A1 __ARID__ struct pOS_MemHeader*);

  UBYTE      mpl_Reserved[16];
};





enum pOS_MemoryFlag
{
  MEMF_ANY     =0x00,       /* Any type of memory will do */
  MEMF_PUBLIC  =0x01,

  MEMF_LOCAL   =0x0100,     /* Memory that does not go away at RESET */
  MEMF_VMEM    =0x0200,     /* Virtual-Memory-Manager may be swap memoryblock */

  MEMF_CLEAR   =0x010000,   /* pOS_AllocMem: NULL out area before return */
  MEMF_LARGEST =0x020000,   /* pOS_AvailMem: return the largest chunk size */
  MEMF_REVERSE =0x040000,   /* pOS_AllocMem: allocate from the top down */
  MEMF_TOTAL   =0x080000,   /* pOS_AvailMem: return total size of memory */

  MEMF_NO_EXPUNGE =0x80000000, /* pOS_AllocMem: Do not cause expunge on failure */

/*----- Current alignment rules for memory blocks (may increase) -----*/
  MEM_BLOCKSIZE  = 8,
  MEM_BLOCKMASK  = (MEM_BLOCKSIZE-1),


  MEMF_CHIP=   0x02,
  MEMF_FAST=   0x04
};


/** pOS_TypeOfMem(,,enum pOS_TypeOfMemoryMode) **/
enum pOS_TypeOfMemoryMode
{
  TOMEMMD_Physics =0 /* Result: MEMF_FAST or MEMF_CHIP, NULL => error (wrong address) */
};






#endif
