public interface IMemoryManager extends IStore, ICounterSetAccess, IAllocationManagerStore
ByteBuffer
s. Typically those buffers
will be allocated on the native process heap.
CAUTION: The memory manager helps you manage direct storage. However,
it does not prevent you from doing something stupid with it. The
most likely error is one in which you get(long)
an address and hold
onto the returned ByteBuffer
after the data at that address has been
freed
. This can leave you in a position where you are
reading on (or writing on!) someone else's data on the JVM native heap. The
memory manager works with DirectBufferPool
s. This class provides the
efficient reuse of direct allocations, but does not release them back to the
JVM. For this reason, if you do stomp on someone's memory, it will not be
memory in use by the JVM but only memory in use by another part of your
application using the same DirectBufferPool
instance.
Modifier and Type | Method and Description |
---|---|
long |
allocate(ByteBuffer data)
Version of
allocate(ByteBuffer, boolean) which is either
blocking or non-blocking depending on whether or not the memory
manager is set in a blocking mode. |
long |
allocate(ByteBuffer data,
boolean blocks)
Allocates space on the backing resource and copies the provided data.
|
long |
allocate(ByteBuffer data,
IAllocationContext context) |
long |
allocate(int nbytes)
Return the address of a new allocation sufficient to store the specified
number of bytes of application data.
|
long |
allocate(int nbytes,
boolean blocks)
Return the address of a new allocation sufficient to store the specified
number of bytes of application data.
|
int |
allocationSize(long addr)
Return the size of the application data for the allocation with the given
address.
|
void |
clear()
Clears all current allocations.
|
IMemoryManager |
createAllocationContext()
Create a child allocation context within which the caller may make and
release allocations.
|
void |
free(long addr)
Frees the address and makes available for recycling
|
void |
free(long addr,
IAllocationContext context) |
ByteBuffer[] |
get(long addr)
Return an array of
ByteBuffer s providing an updatable view onto
the backing allocation. |
long |
getAllocationCount()
The #of allocation spanned by this allocation context (including any
any child allocation contexts).
|
int |
getMaxSectors()
The maximum number of backing buffers which may be allocated by the
IMemoryManager and Integer.MAX_VALUE if there is no
effective limit on the #of backing buffers which may be allocated. |
long |
getPhysicalAddress(long addr)
Determine the unencoded physical address
|
int |
getSectorCount()
The #of backing buffers in use.
|
int |
getSectorSize()
The size of a backing buffer in bytes.
|
long |
getSlotBytes()
Return the #of bytes of consumed by allocation slots allocated against
this
IMemoryManager (including any child allocation contexts). |
long |
getUserBytes()
Return the #of bytes of application data allocated against this
IMemoryManager (including any child allocation contexts). |
boolean |
isCommitted(long addr)
Return
true iff the allocation having that address is
flagged as committed. |
byte[] |
read(long addr)
Return a copy of the data stored at that address.
|
alloc, close, commit, free, getAssociatedSlotSize, getCommitLock, getData, getStoreFile, postCommit
abortContext, detachContext, newAllocationContext
checkDeferredFrees, getLastReleaseTime, newTx, registerExternalCache, saveDeferrals
getCounters
delete, getOutputStream, write
getInputStream, getOutputStream
long allocate(ByteBuffer data, boolean blocks)
data
- The data will be copied to the backing resource. For each
buffer in this array, the position will be advanced to the
limit.blocks
- When true
the request will block until the memory
is available for the allocation.IllegalArgumentException
- if data is null
.IllegalArgumentException
- if Buffer.remaining()
is ZERO (0).MemoryManagerResourceError
- If the memory is not available for the allocation and
blocks:=false. Whether or not this exception can be
thrown depends on whether the backing buffer pool has a
bounded capacity and whether the IMemoryManager
using
that pool has a bounded capacity.long allocate(ByteBuffer data)
allocate(ByteBuffer, boolean)
which is either
blocking or non-blocking depending on whether or not the memory
manager is set in a blocking mode.data
- The data will be copied to the backing resource. For each
buffer in this array, the position will be advanced to the
limit.IllegalArgumentException
- if data is null
.IllegalArgumentException
- if Buffer.remaining()
is ZERO (0).MemoryManagerResourceError
- If the memory is not available for the allocation and
blocks:=false. Whether or not this exception can be
thrown depends on whether the backing buffer pool has a
bounded capacity and whether the IMemoryManager
using
that pool has a bounded capacity.long allocate(int nbytes, boolean blocks)
nbytes
- The size of the allocation request.blocks
- When true
the method will block until the
allocation request can be satisfied. When false
a
MemoryManagerOutOfMemory
will be thrown.IllegalArgumentException
- if nbytes is non-positive.MemoryManagerResourceError
- If the memory is not available for the allocation and
blocks:=false. Whether or not this exception can be
thrown depends on whether the backing buffer pool has a
bounded capacity and whether the IMemoryManager
using
that pool has a bounded capacity.long allocate(int nbytes)
allocate(int)
.nbytes
- The size of the allocation request.blocks
- When true
the method will block until the
allocation request can be satisfied. When false
a
MemoryManagerOutOfMemory
will be thrown.IllegalArgumentException
- if nbytes is non-positive.MemoryManagerResourceError
- If the memory is not available for the allocation and
blocks:=false. Whether or not this exception can be
thrown depends on whether the backing buffer pool has a
bounded capacity and whether the IMemoryManager
using
that pool has a bounded capacity.long allocate(ByteBuffer data, IAllocationContext context)
ByteBuffer[] get(long addr)
ByteBuffer
s providing an updatable view onto
the backing allocation.
The ByteBuffer[] return enables the handling of blobs that span more than
a single slot, without the need to create an intermediate ByteBuffer.
This method is designed for use with zero-copy NIO. Furthermore, since
the ByteBuffer
s in the returned array are not read-only, they can
be updated directly. In this way the allocate(int)
can be used
in conjunction with get to provide more flexibility when storing data.
Using ByteBuffer:put the returned array can be efficiently copied to another ByteBuffer:
ByteBuffer mybb; ByteBuffer[] bufs = get(addr); for (ByteBuffer b : bufs) { mybb.put(b); }CAUTION: Do not hold onto the
ByteBuffer
longer than is
necessary. If the allocation is released by free(long)
or clear()
, then the memory backing the ByteBuffer
could
be reallocated by another DirectBufferPool
consumer.addr
- An previously allocated address.byte[] read(long addr)
IMemoryManager
is treated as a
persistence store.addr
- The address.void free(long addr)
addr
- to be freedIllegalArgumentException
- If the address is known to be invalid (never written or
deleted). Note that the address 0L is always invalid as
is any address which encodes a 0 byte length.void free(long addr, IAllocationContext context)
void clear()
IMemoryManager
will release
any direct ByteBuffer
s back to the pool from which they were
allocated.
CAUTION: Do not clear an allocation context until you know that all threads with access to that allocation context have either been terminated or released their reference to that allocation context.
IMemoryManager createAllocationContext()
IAllocationContext
as well (that
is, why does IMemoryManager
not extend IAllocationContext
). Also, note that IStore.commit()
is similar to
IAllocationManager.detachContext(IAllocationContext)
.int allocationSize(long addr)
addr
- The address.long getAllocationCount()
long getUserBytes()
IMemoryManager
(including any child allocation contexts). Due to
the overhead of the storage allocation scheme, this value may be smaller
than getSlotBytes()
.long getSlotBytes()
IMemoryManager
(including any child allocation contexts).int getSectorSize()
int getSectorCount()
int getMaxSectors()
IMemoryManager
and Integer.MAX_VALUE
if there is no
effective limit on the #of backing buffers which may be allocated.boolean isCommitted(long addr)
true
iff the allocation having that address is
flagged as committed. The caller must be holding the allocation lock in
order for the result to remain valid outside of the method call.addr
- The address.true
iff the address is currently committed.long getPhysicalAddress(long addr)
addr
- The encoded addressCopyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.