//#include "Global.h"
#include <Global/Main_Global.h>

BOOL Startup_MemoryManager( void )
{
    App->MemoryPool = CreatePool(MEMF_PUBLIC|MEMF_CLEAR,32768,16384);
    if(App->MemoryPool)
      return(TRUE);
     else
      return(FALSE);
}

void Shutdown_MemoryManager(void )
{

    if(App->MemoryPool)
    {
       DeletePool(App->MemoryPool);
    }
    else
     printf("Problem with the pool\n Maybe it needs drained?\n");
    
}
APTR Allocate_Memory(ULONG Amount)
{
   APTR Memory;
   Memory = AllocVecPooled(App->MemoryPool,Amount);
   if(Memory)
       {
        return(Memory);
       }
   else
    {
       DisplayBeep(0);
       printf("Very Low On Memory, Please Reboot!\n");
       return(NULL);
    }
      
}

void Free_Memory( APTR Memory)
{
      FreeVecPooled(Memory);
      
}

APTR AllocVecPooled( APTR pool, ULONG size )
{
        ULONG *memblock;

        if( !pool || !size ) return( NULL );

        if( !(memblock = AllocPooled( pool, size + 2*sizeof(APTR) ) ) )
                return( NULL );

        *memblock++ = (ULONG) pool;
        *memblock++ = size + 2*sizeof( APTR );

        return( memblock );
}

void FreeVecPooled( APTR memblock )
{
        ULONG *m = memblock;
        APTR pool;
        ULONG size;

        if( m )
        {
                size = *--m;
                pool = (APTR) *--m;
                FreePooled( pool, m, size );
        }
}       






