-------------------------------------------------------------------------

Copyright 2007 Richard J. Gaydos.

-------------------------------------------------------------------------

Module: Allocate & Free Memory

-------------------------------------------------------------------------
 
Allocate Memory Algorithm for Fixed Partitioning:

-------------------------------------------------------------------------

Allocate_Memory(Size_Of_Job, PCB_Address)

Returns	-1		If the Job can NEVER run on this system
Returns  Location	If the Job can run NOW
Blocks the Task		If the Job must WAIT, then RETURNS  Location 
                           when  FREE
						
-------------------------------------------------------------------------
 
P(Memory_List_Semaphore, PCB_Address)

IF  Size_Of_Job > Biggest Partition THEN
    V(Memory_List_Semaphore)
    RETURN (-1)
 
Start at beginning of FPT
 
DO WHILE There are entries in FPT
   IF Status = AV THEN
      IF Size_Of_Slot >= Size_Of_Job THEN
         Mark  Status = AL
	 V(Memory_List_Semaphore)
         RETURN  Location
END
 
V(Memory_List_Semaphore)

Update Memory_Wait_Table
       Place PCB_Address and Size_Of_Job in   AV  Slot
       Mark Status as   AL
       P(Memory_Wait_Semaphore, PCB_Address)

RETURN  Location

-------------------------------------------------------------------------
 
Free Memory Algorithm for Fixed Partitioning
 
-------------------------------------------------------------------------

Free_Memory(Location_of_Code)

-------------------------------------------------------------------------

P(Memory_List_Semaphore, PCB_Address)

Find Location_of_Job  in  FPT, mark Status = AV
 
IF Memory Wait Semaphore < 0
   Check Memory_Wait_SemaphoreÕs List for first Size <= Size of
                                                        Newly-Freed Area
 
   IF found THEN
      Mark Status = AV  in Memory_Wait_Table
      Mark Status = AL   in FPT
      V(Memory_Wait_Semaphore)

   Note: Location will be returned by whoever was waiting for it

V(Memory_List_Semaphore)

-------------------------------------------------------------------------