public class AppendableMemory extends Object implements Closeable
MemoryAllocator
. Useful for situations where you don't know ahead of time
exactly how much memory you'll need.Modifier and Type | Method and Description |
---|---|
void |
advanceCursor(int bytes)
Advances the cursor a certain number of bytes.
|
void |
clear() |
void |
close() |
static AppendableMemory |
create(MemoryAllocator allocator)
Creates an appendable memory instance with a default initial allocation size.
|
static AppendableMemory |
create(MemoryAllocator allocator,
int initialAllocationSize)
Creates an appendable memory instance using a particular initial allocation size.
|
MemoryRange<org.apache.datasketches.memory.WritableMemory> |
cursor()
Return a pointer to the current cursor location, which is where the next elements should be written.
|
boolean |
reserveAdditional(int bytes)
Ensure that at least "bytes" amount of space is available after the cursor.
|
void |
rewindCursor(int bytes)
Rewinds the cursor a certain number of bytes, effectively erasing them.
|
long |
size() |
long |
writeTo(org.apache.datasketches.memory.WritableMemory memory,
long startPosition)
Write current memory to a
WritableMemory buffer. |
public static AppendableMemory create(MemoryAllocator allocator)
reserveAdditional(int)
can accept allocations of that size and
remain fully-packed.public static AppendableMemory create(MemoryAllocator allocator, int initialAllocationSize)
public MemoryRange<org.apache.datasketches.memory.WritableMemory> cursor()
advanceCursor(int)
and rewindCursor(int)
.
The start of the returned range is the cursor location; the end is the end of the current Memory block.
The returned Memory object is in little-endian order.public boolean reserveAdditional(int bytes)
advanceCursor(int)
with
the amount of memory written.public void advanceCursor(int bytes)
reserveAdditional(int)
, then write to the memory, then call advanceCursor with
the amount of memory written.public void rewindCursor(int bytes)
advanceCursor(int)
.public long size()
public long writeTo(org.apache.datasketches.memory.WritableMemory memory, long startPosition)
WritableMemory
buffer.public void clear()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.