de.sciss.jcollider
Class ContiguousBlockAllocator

java.lang.Object
  extended by de.sciss.jcollider.ContiguousBlockAllocator
All Implemented Interfaces:
BlockAllocator

public class ContiguousBlockAllocator
extends java.lang.Object
implements BlockAllocator

Quite a 1:1 translation from the SClang class written by James Harkins, this class is a robust allocator for busses in a dynamic environment. It does not exhibit the fragmentation problem of the PowerOfTwoAllocator.

Version:
0.32, 25-Feb-08
Author:
Hanns Holger Rutz
Todo:
freed should be a sorted Map !! then findAvailable could be faster
Warning:
this class has not been thoroughly debugged

Nested Class Summary
static class ContiguousBlockAllocator.Factory
           
 
Constructor Summary
ContiguousBlockAllocator(int size)
           
ContiguousBlockAllocator(int size, int pos)
           
 
Method Summary
 int alloc()
           
 int alloc(int n)
          Allocates a new bus.
 void debug()
           
 void free(int address)
          Frees a bus, that is makes it available again for new re-allocation.
 java.util.List getAllocatedBlocks()
          Queries a list of allocated blocks.
 de.sciss.jcollider.ContiguousBlockAllocator.Block reserve(int address)
           
 de.sciss.jcollider.ContiguousBlockAllocator.Block reserve(int address, int size)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContiguousBlockAllocator

public ContiguousBlockAllocator(int size)

ContiguousBlockAllocator

public ContiguousBlockAllocator(int size,
                                int pos)
Method Detail

alloc

public int alloc()

alloc

public int alloc(int n)
Description copied from interface: BlockAllocator
Allocates a new bus.

Specified by:
alloc in interface BlockAllocator
Parameters:
n - the number of channels to allocate. must be greater than zero.
Returns:
the address or index of the bus which is the index of the first channel. returns -1 if the allocator ran out of busses.

reserve

public de.sciss.jcollider.ContiguousBlockAllocator.Block reserve(int address)

reserve

public de.sciss.jcollider.ContiguousBlockAllocator.Block reserve(int address,
                                                                 int size)

free

public void free(int address)
Description copied from interface: BlockAllocator
Frees a bus, that is makes it available again for new re-allocation.

Specified by:
free in interface BlockAllocator
Parameters:
address - the index of the bus

getAllocatedBlocks

public java.util.List getAllocatedBlocks()
Description copied from interface: BlockAllocator
Queries a list of allocated blocks. This can be usefull for debugging purposes.

Specified by:
getAllocatedBlocks in interface BlockAllocator
Returns:
a list whose elements are instances of Block

debug

public void debug()