com.unister.semweb.drums.bucket
Class DynamicMemoryAllocater<Data extends AbstractKVStorable>

java.lang.Object
  extended by com.unister.semweb.drums.bucket.DynamicMemoryAllocater<Data>
Type Parameters:
Data - an implementation of AbstractKVStorable, e.g. GeneralStorable

public class DynamicMemoryAllocater<Data extends AbstractKVStorable>
extends java.lang.Object

This class manages the dynamic distribution of memory for the Buckets. It should be used as Singelton. This class doesn't really allocate memory. It just allows to manage virtual memory. An object which wants to be controlled easily asks for memory. This object also must give a report, when it doesn't need this memory anymore.

Author:
Martin Nettling

Field Summary
static DynamicMemoryAllocater[] INSTANCES
          An array, containing all instances of DynamicMemoryAllocater.
 
Method Summary
 int allocateNextChunk()
          This method tries to mark memory as allocated.
 void freeMemory(long size)
          Marks the given amount of memory as free to use.
 long getFreeMemory()
           
 long getMaxMemory()
           
 long getUsedMemory()
           
static
<Data extends AbstractKVStorable>
void
instantiate(DRUMSParameterSet<Data> gp)
          Instantiates the DynamicMemoryAllocater, only if there is not already an instance
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCES

public static DynamicMemoryAllocater[] INSTANCES
An array, containing all instances of DynamicMemoryAllocater. Each DRUMS-table has its own.

Method Detail

instantiate

public static <Data extends AbstractKVStorable> void instantiate(DRUMSParameterSet<Data> gp)
Instantiates the DynamicMemoryAllocater, only if there is not already an instance

Parameters:
gp - a pointer to the GlobalParameters used by this DRUMS

allocateNextChunk

public int allocateNextChunk()
This method tries to mark memory as allocated. It allocates as much bytes as defined in MEMORY_CHUNK and returns the number of bytes marked as allocated. This method doesn't really allocate memory.

Returns:
the size of the allocated chunk

freeMemory

public void freeMemory(long size)
Marks the given amount of memory as free to use.

Parameters:
size - the size of memory (in bytes) to free

getUsedMemory

public long getUsedMemory()
Returns:
the number of used bytes, allocated by this DynamicMemoryAllocater

getMaxMemory

public long getMaxMemory()
Returns:
the maximal allowed bytes to be used by this DynamicMemoryAllocater

getFreeMemory

public long getFreeMemory()
Returns:
the number of bytes not allocated by the DynamicMemoryAllocater