Class BBAlloc

java.lang.Object
net.sodacan.core.util.BBAlloc
All Implemented Interfaces:
Closeable, AutoCloseable

public class BBAlloc extends Object implements Closeable
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Use an existing bytebuffer
    BBAlloc(ByteBuffer space, int refMax, int spaceMax)
     
    BBAlloc(BBAlloc src, ByteBuffer space, int refMax, int spaceMax)
    Copy constructor, compacting space as we go
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    alloc(int size)
    Allocate space and return a reference to it.
    void
     
    int
    The number of references allocated
    fetch(int ref)
    Store a string and return a reference to it
    int
    getAddress(int ref)
    Return an address in space, the address is the actual data, not including the length
    int
    getSize(int ref)
    Return the size of a particular allocation which could be zero if there is none yet.
    int
     
    int
    The amount of space that can no longer be allocated (without some effort)
    protected void
    replace(int ref, String src)
    We already have an item stored, we need to replace the value stored there.
    void
    Must remain in sync with restoreHeader.
    void
    setPointerAddress(int ref, int offset)
     
    void
    store(Integer ref, String src)
    Store a string at the supplied reference
    int
    Store a string and return a reference to it

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • BBAlloc

      public BBAlloc(ByteBuffer space)
      Use an existing bytebuffer
      Parameters:
      space -
    • BBAlloc

      public BBAlloc(ByteBuffer space, int refMax, int spaceMax)
    • BBAlloc

      public BBAlloc(BBAlloc src, ByteBuffer space, int refMax, int spaceMax)
      Copy constructor, compacting space as we go
      Parameters:
      src -
      space -
  • Method Details

    • saveHeader

      public void saveHeader()
      Must remain in sync with restoreHeader. Also, version must be first so we can decide if we need to upgrade something
    • setPointerAddress

      public void setPointerAddress(int ref, int offset)
    • alloc

      public int alloc(int size)
      Allocate space and return a reference to it. We always allocate INT_SIZE extra bytes to hold the length of the allocation.
      Parameters:
      size - of the space requested or zero to just reserve a reference
      Returns:
    • getAddress

      public int getAddress(int ref)
      Return an address in space, the address is the actual data, not including the length
      Parameters:
      ref -
      Returns:
    • getSize

      public int getSize(int ref)
      Return the size of a particular allocation which could be zero if there is none yet.
      Parameters:
      ref -
      Returns:
    • store

      public int store(String src)
      Store a string and return a reference to it
      Parameters:
      src -
      Returns:
    • store

      public void store(Integer ref, String src)
      Store a string at the supplied reference
      Parameters:
      ref -
      src -
    • replace

      protected void replace(int ref, String src)
      We already have an item stored, we need to replace the value stored there.
      Parameters:
      ref -
      src -
    • count

      public int count()
      The number of references allocated
      Returns:
    • fetch

      public String fetch(int ref)
      Store a string and return a reference to it
      Parameters:
      ref -
      Returns:
    • getWastedSpace

      public int getWastedSpace()
      The amount of space that can no longer be allocated (without some effort)
      Returns:
    • getSpaceUsed

      public int getSpaceUsed()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException