Package net.sodacan.core.util
Class BBAlloc
java.lang.Object
net.sodacan.core.util.BBAlloc
- All Implemented Interfaces:
Closeable
,AutoCloseable
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
Constructor Summary
ConstructorsConstructorDescriptionBBAlloc
(ByteBuffer space) Use an existing bytebufferBBAlloc
(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 TypeMethodDescriptionint
alloc
(int size) Allocate space and return a reference to it.void
close()
int
count()
The number of references allocatedfetch
(int ref) Store a string and return a reference to itint
getAddress
(int ref) Return an address in space, the address is the actual data, not including the lengthint
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
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 a string at the supplied referenceint
Store a string and return a reference to it
-
Field Details
-
HEADER_SIZE
public static final int HEADER_SIZE- See Also:
-
INT_SIZE
public static final int INT_SIZE- See Also:
-
MAGIC_NUMBER
public static final int MAGIC_NUMBER- See Also:
-
-
Constructor Details
-
BBAlloc
Use an existing bytebuffer- Parameters:
space
-
-
BBAlloc
-
BBAlloc
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
Store a string and return a reference to it- Parameters:
src
-- Returns:
-
store
Store a string at the supplied reference- Parameters:
ref
-src
-
-
replace
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
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
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-