Methoden
Class Buddy

java.lang.Object
  |
  +--Methoden.AllocationMethod
        |
        +--Methoden.Buddy

public class Buddy
extends AllocationMethod

Implementation of the allocation method Buddy-System. The selected memory area for allocation is the first free memory area with sufficient size. The search for this memory area starts the first time at the first free memory area. Every succeding search continues at the last resulting free memory area if one exist, else at the next free memory area following the allocated one. The free memory areas are sorted ascending by the starting position in memory.


Field Summary
static java.lang.String LONGNAME
          Short name of this allocation method
static java.lang.String SHORTNAME
          Long name of this allocation method
 
Fields inherited from class Methoden.AllocationMethod
longName, shortName
 
Constructor Summary
Buddy()
          Buddy-System is an implementation of the allocatio method class and searches for the next avalable free memory area starting from the beginning of memory and resuming the search each time at the last stop point.
 
Method Summary
 void appendMemoryArea(Memory usedMemory, MemoryArea newMemoryArea)
          Appends a new memory area into the memory structure.
static Memory buildFlatMemory(Memory usedMemory)
          Build up a flat memory.
 Memory buildFreeMemory(Memory usedMemory)
          Build up a free memory according to the given used memory.
 Memory createRandomUsedMemory(Memory usedMemory)
          Creates a new random used memory regarding the specific needs to the memory structure of the buddy system.
 Memory createUsedMemory(int newMemoryAreaCount, int newMemorySize)
          Creates a new empty used memory.
private  MemoryArea getBuddy(MemoryArea memoryArea)
          Returns the corresponding buddy of the given memoryArea.
 MemoryArea getFreeArea(Memory freeMemory, int reqSize)
          Returns the first free memory area where the requestedSize fits into.
 int getFreeAreasCount(Memory freeMemory)
          Returns the number of free memory areas.
 boolean isUseFullFreeMemoryArea()
          Returns true, if the full free memory area should be used.
 void mergeMemoryArea(Memory freeMemory, MemoryArea mergeMemoryArea)
          Merge the given free memoryArea with the given free memory.
 void removeMemoryArea(Memory memory, int startPos)
          Removes the requested memoryArea in the given memory
 
Methods inherited from class Methoden.AllocationMethod
getIntFrag, getLongName, getShortName, getUsage, removeMemoryAreaProcess, sortFreeMemory, sortUsedMemory
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

SHORTNAME

public static final java.lang.String SHORTNAME
Long name of this allocation method

LONGNAME

public static final java.lang.String LONGNAME
Short name of this allocation method
Constructor Detail

Buddy

public Buddy()
Buddy-System is an implementation of the allocatio method class and searches for the next avalable free memory area starting from the beginning of memory and resuming the search each time at the last stop point.
Method Detail

createUsedMemory

public Memory createUsedMemory(int newMemoryAreaCount,
                               int newMemorySize)
Creates a new empty used memory.
Overrides:
createUsedMemory in class AllocationMethod

createRandomUsedMemory

public Memory createRandomUsedMemory(Memory usedMemory)
Creates a new random used memory regarding the specific needs to the memory structure of the buddy system.
Overrides:
createRandomUsedMemory in class AllocationMethod

buildFreeMemory

public Memory buildFreeMemory(Memory usedMemory)
Build up a free memory according to the given used memory.
Overrides:
buildFreeMemory in class AllocationMethod

buildFlatMemory

public static Memory buildFlatMemory(Memory usedMemory)
Build up a flat memory. Collect all memoryAreas in the memoryVector and append them to the "main Vector".

appendMemoryArea

public void appendMemoryArea(Memory usedMemory,
                             MemoryArea newMemoryArea)
Appends a new memory area into the memory structure. The new memoryArea is appended to the memory in the vector with the
Overrides:
appendMemoryArea in class AllocationMethod

getFreeAreasCount

public int getFreeAreasCount(Memory freeMemory)
Returns the number of free memory areas.
Overrides:
getFreeAreasCount in class AllocationMethod

getFreeArea

public MemoryArea getFreeArea(Memory freeMemory,
                              int reqSize)
Returns the first free memory area where the requestedSize fits into. Cases: 1. None was found, return null 2. A free memoryArea with exact size was found, return the free memory area and remove it from the free memory 3. A free memoryArea with bigger size was foung, divide the big area into 2 half-sized memory areas until the exact of the request is found. Return the memory area with the exact size and removeit from the free memory.
Overrides:
getFreeArea in class AllocationMethod

isUseFullFreeMemoryArea

public boolean isUseFullFreeMemoryArea()
Returns true, if the full free memory area should be used.
Overrides:
isUseFullFreeMemoryArea in class AllocationMethod

getBuddy

private MemoryArea getBuddy(MemoryArea memoryArea)
Returns the corresponding buddy of the given memoryArea.

mergeMemoryArea

public void mergeMemoryArea(Memory freeMemory,
                            MemoryArea mergeMemoryArea)
Merge the given free memoryArea with the given free memory.
Overrides:
mergeMemoryArea in class AllocationMethod

removeMemoryArea

public void removeMemoryArea(Memory memory,
                             int startPos)
Removes the requested memoryArea in the given memory
Overrides:
removeMemoryArea in class AllocationMethod