Speicher
Class Memory

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--Speicher.Memory
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.io.Serializable

public class Memory
extends java.util.Vector

This class simulates the memory structure and provides methods to handle the memory areas in this memory structure. The number of areas isn't fix and can be changed at runtime. To set up the maximum memory size (512 MB) the constants for the memory size have to be added and the number of memory vectors has to be increased.

See Also:
Serialized Form

Field Summary
private static java.awt.Color[] AREAFILLEDCOLOR
          Colors to fill the memory areas different.
private static int CYAN
          Index of this color for handling the use of colors.
private static int GREEN
          Index of this color for handling the use of colors.
private  java.lang.String lastMethod
          Last used allocation method.
private  java.lang.String lastRequestString
          Last request as a String for drawing the development of the memory history.
private  int lastRequestType
          Type of the last request.
private static int MAGENTA
          Index of this color for handling the use of colors.
private  int memorySize
          Actual size of Memory as an int-value.
private  Memory[] memorySizeVector
          Vectors for the memory management in the allocation method "buddy system".
private static int ORANGE
          Index of this color for handling the use of colors.
private static int PINK
          Index of this color for handling the use of colors.
private static int RED
          Index of this color for handling the use of colors.
static int SIZE_128_MB
          Memory size 128 MB to calculate for drawing.
static int SIZE_256_MB
          Memory size 256 MB to calculate for drawing.
static int SIZE_32_MB
          Memory size 32 MB to calculate for drawing.
static int SIZE_512_MB
          Memory size 512 MB to calculate for drawing.
static int SIZE_64_MB
          Memory size 64 MB to calculate for drawing.
private  int[] usedColors
          Counters for each use of a color in a memory area.
private static int WHITE
          Index of this color for handling the use of colors.
private static int YELLOW
          Index of this color for handling the use of colors.
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData, serialVersionUID
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Memory()
          Create a new instance of this Memory.
Memory(int newMemoryAreaCount, int newMemorySize)
          Create a new instance of Memory with given number of memory areas and the given memorySize.
 
Method Summary
 void appendMemoryArea(MemoryArea newMemoryArea)
          Appends a new memory area into the memory structure
 void appendMemoryAreas(int deltaMemoryAreaCount)
          Appends the given number of initial memory areas to the memory.
static Memory buildFreeMemory(Memory usedMemory)
          Builds a memory structure containing the free memory areas depending on the given usedMemory.
 Memory createRandomMemory()
          Create a new instance of Memory with random values.
 void decColorUse(java.awt.Color color)
          Decreases the use of the given Color by one.
 Memory deepCopy()
          Creates a deep copy of memory.
private  boolean fitInMemory(Memory memory, MemoryArea newMA)
          Checks, if the given memory area does fit in this memory.
 int getIndexOfMemoryArea(MemoryArea memoryArea)
          Returns the index of the given memory area.
 java.lang.String getLastMethod()
          Returns the text of the last used allocation method.
 java.lang.String getLastRequestString()
          Returns the text of the last request.
 int getLastRequestType()
          Returns the type of the last request.
 MemoryArea getMemoryArea(int index)
          Returns the memory area at a special index.
 int getMemoryAreaCount()
          Returns the number of memory areas in this memory.
 int getMemoryAreaFilledCount()
          Returns the number of not initial memory areas in this memory.
 MemoryArea getMemoryAreaPos(int memoryPos)
          Returns the memory area that contains the given memory position or if none exists, return the first free memory area.
 MemoryArea getMemoryAreaProcess(int processNr)
          Returns the memory area with the given process number.
 MemoryArea getMemoryAreaStart(int startPos)
          Returns the memory area with a special starting position.
 int getMemoryAreaTotalUsedSize()
          Returns the total size of all not initial memory areas.
 int getMemoryAreaTotaSize()
          Returns the total size of all not initial memory areas.
 int getMemorySize()
          Returns the size of this memory.
 Memory getMemorySizeVector(int index)
          Returns the memory in the memorySizeVector with the given index.
 int getMemorySizeVectorLength()
          Returns the length of memorySizeVector.
 int getMinIndexColor()
          Returns the index of the color with the lowest use.
 java.awt.Color getNextColor()
          Returns a color that is not to often used in this memory.
 void insertMemoryArea(MemoryArea newMemoryArea)
          Inserts a new memory area into the memory structure regarding the sort starting position
 boolean isInitial()
          Returns true, if the memory has only initial memory areas.
 boolean isInMemory(int startingPos)
          Returns true, if a memory area with the given starting position is in memory.
 boolean isInMemoryProcess(int processNr)
          Returns true, if a memory area with the given processNumber is in memory.
 void mergeFreeMemoryArea(MemoryArea memoryArea)
          Merges the given memory are with any other existing or adds it to the list.
 void printMemory()
           
 void printMemoryBuddy()
           
 void removeAllMemoryAreas()
          Removes all memory areas from memory.
 void removeMemoryArea(int startPos)
          Removes memory area from memory woth the given starting position.
 void removeMemoryAreaProcess(int processNr)
          Removes memory area from memory with the given process number.
 void resetColorUse()
          Reset the use of olors.
 void setLastMethod(java.lang.String newLastMethod)
          Sets the last used allocation method.
 void setLastRequest(int newLastRequestType, java.lang.String newLastRequest)
          Sets the last request to this memory.
 void setMemorySize(int newMemorySize)
          Sets the size of this memory.
 void setMemorySizeVector(Memory newMemory, int index)
          Sets the given memory in the memorySizeVector at the given index.
 void sortAscProcess()
          Sorts the memory allocations ascending by the processNr.
 void sortAscSize()
          Sorts the memory allocations ascending by the size.
 void sortAscStart()
          Sorts the memory allocations ascending by the starting position.
 void sortDescSize()
          Sorts the memory allocations descending by the size.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, ensureCapacityHelper, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

AREAFILLEDCOLOR

private static final java.awt.Color[] AREAFILLEDCOLOR
Colors to fill the memory areas different.

WHITE

private static final int WHITE
Index of this color for handling the use of colors.

GREEN

private static final int GREEN
Index of this color for handling the use of colors.

RED

private static final int RED
Index of this color for handling the use of colors.

ORANGE

private static final int ORANGE
Index of this color for handling the use of colors.

MAGENTA

private static final int MAGENTA
Index of this color for handling the use of colors.

CYAN

private static final int CYAN
Index of this color for handling the use of colors.

PINK

private static final int PINK
Index of this color for handling the use of colors.

YELLOW

private static final int YELLOW
Index of this color for handling the use of colors.

usedColors

private int[] usedColors
Counters for each use of a color in a memory area.

SIZE_32_MB

public static final int SIZE_32_MB
Memory size 32 MB to calculate for drawing.

SIZE_64_MB

public static final int SIZE_64_MB
Memory size 64 MB to calculate for drawing.

SIZE_128_MB

public static final int SIZE_128_MB
Memory size 128 MB to calculate for drawing.

SIZE_256_MB

public static final int SIZE_256_MB
Memory size 256 MB to calculate for drawing.

SIZE_512_MB

public static final int SIZE_512_MB
Memory size 512 MB to calculate for drawing.

lastMethod

private java.lang.String lastMethod
Last used allocation method.

lastRequestType

private int lastRequestType
Type of the last request.

lastRequestString

private java.lang.String lastRequestString
Last request as a String for drawing the development of the memory history.

memorySize

private int memorySize
Actual size of Memory as an int-value.

memorySizeVector

private Memory[] memorySizeVector
Vectors for the memory management in the allocation method "buddy system". Each vector contains the memory areas with a special size. The sizes are a power of two: 2^0, 2^1, 2^2, ... 2^9 for example. These entries are used for the buddy system. They are also added to the flat structur of this class, the "main vector". This is done to have a similar place where all memory areas can be accessed
Constructor Detail

Memory

public Memory()
Create a new instance of this Memory.

Memory

public Memory(int newMemoryAreaCount,
              int newMemorySize)
Create a new instance of Memory with given number of memory areas and the given memorySize.
Method Detail

printMemory

public void printMemory()

printMemoryBuddy

public void printMemoryBuddy()

getMinIndexColor

public int getMinIndexColor()
Returns the index of the color with the lowest use.

deepCopy

public Memory deepCopy()
Creates a deep copy of memory. All elements are new created References to elements are solved and these elements are new created! The new Memory is independent from the old one! This function isn't implemented in standard java!

decColorUse

public void decColorUse(java.awt.Color color)
Decreases the use of the given Color by one.

resetColorUse

public void resetColorUse()
Reset the use of olors.

getNextColor

public java.awt.Color getNextColor()
Returns a color that is not to often used in this memory.

createRandomMemory

public Memory createRandomMemory()
Create a new instance of Memory with random values.

buildFreeMemory

public static Memory buildFreeMemory(Memory usedMemory)
Builds a memory structure containing the free memory areas depending on the given usedMemory.

mergeFreeMemoryArea

public void mergeFreeMemoryArea(MemoryArea memoryArea)
Merges the given memory are with any other existing or adds it to the list.

appendMemoryArea

public void appendMemoryArea(MemoryArea newMemoryArea)
Appends a new memory area into the memory structure

insertMemoryArea

public void insertMemoryArea(MemoryArea newMemoryArea)
Inserts a new memory area into the memory structure regarding the sort starting position

isInitial

public boolean isInitial()
Returns true, if the memory has only initial memory areas.

isInMemoryProcess

public boolean isInMemoryProcess(int processNr)
Returns true, if a memory area with the given processNumber is in memory.

isInMemory

public boolean isInMemory(int startingPos)
Returns true, if a memory area with the given starting position is in memory.

appendMemoryAreas

public void appendMemoryAreas(int deltaMemoryAreaCount)
Appends the given number of initial memory areas to the memory.

removeAllMemoryAreas

public void removeAllMemoryAreas()
Removes all memory areas from memory.

removeMemoryAreaProcess

public void removeMemoryAreaProcess(int processNr)
Removes memory area from memory with the given process number.

removeMemoryArea

public void removeMemoryArea(int startPos)
Removes memory area from memory woth the given starting position.

fitInMemory

private boolean fitInMemory(Memory memory,
                            MemoryArea newMA)
Checks, if the given memory area does fit in this memory. It does not overlap with the exisiting memory areas and the size must be appropriate.

getLastRequestType

public int getLastRequestType()
Returns the type of the last request.

getLastRequestString

public java.lang.String getLastRequestString()
Returns the text of the last request.

getLastMethod

public java.lang.String getLastMethod()
Returns the text of the last used allocation method.

getMemorySizeVector

public Memory getMemorySizeVector(int index)
Returns the memory in the memorySizeVector with the given index. Only needed for buddy system.

getMemorySizeVectorLength

public int getMemorySizeVectorLength()
Returns the length of memorySizeVector. Only needed for buddy system.

setMemorySizeVector

public void setMemorySizeVector(Memory newMemory,
                                int index)
Sets the given memory in the memorySizeVector at the given index. Only needed for buddy system.

getMemoryArea

public MemoryArea getMemoryArea(int index)
Returns the memory area at a special index.

getIndexOfMemoryArea

public int getIndexOfMemoryArea(MemoryArea memoryArea)
Returns the index of the given memory area.

getMemoryAreaTotalUsedSize

public int getMemoryAreaTotalUsedSize()
Returns the total size of all not initial memory areas.

getMemoryAreaTotaSize

public int getMemoryAreaTotaSize()
Returns the total size of all not initial memory areas.

getMemoryAreaProcess

public MemoryArea getMemoryAreaProcess(int processNr)
Returns the memory area with the given process number.

getMemoryAreaStart

public MemoryArea getMemoryAreaStart(int startPos)
Returns the memory area with a special starting position.

getMemoryAreaPos

public MemoryArea getMemoryAreaPos(int memoryPos)
Returns the memory area that contains the given memory position or if none exists, return the first free memory area.

getMemoryAreaCount

public int getMemoryAreaCount()
Returns the number of memory areas in this memory.

getMemoryAreaFilledCount

public int getMemoryAreaFilledCount()
Returns the number of not initial memory areas in this memory.

getMemorySize

public int getMemorySize()
Returns the size of this memory.

setMemorySize

public void setMemorySize(int newMemorySize)
Sets the size of this memory.

setLastRequest

public void setLastRequest(int newLastRequestType,
                           java.lang.String newLastRequest)
Sets the last request to this memory.

setLastMethod

public void setLastMethod(java.lang.String newLastMethod)
Sets the last used allocation method.

sortDescSize

public void sortDescSize()
Sorts the memory allocations descending by the size.

sortAscSize

public void sortAscSize()
Sorts the memory allocations ascending by the size.

sortAscProcess

public void sortAscProcess()
Sorts the memory allocations ascending by the processNr.

sortAscStart

public void sortAscStart()
Sorts the memory allocations ascending by the starting position.