FileDocCategorySizeDatePackage
DirectByteBuffers.javaAPI DocAndroid 1.5 API3298Wed May 06 22:41:04 BST 2009java.nio

DirectByteBuffers

public class DirectByteBuffers extends Object
Helper class for operations on direct ByteBuffer
see
java.nio.ByteBuffer

Fields Summary
Constructors Summary
Methods Summary
public static voidfree(java.nio.ByteBuffer directBuffer)
Explicitly frees the memory used by the given direct byte buffer.

If the memory is known to already have been freed then this is a no-op. Once the memory has been freed then operations requiring access to the memory will throw an IllegalStateException.

Note this is is possible that the memory is freed by code that reaches into the address and explicitly frees it 'beneith' us -- this is bad form.

param
directBuffer the direct byte buffer memory to free
throws
IllegalArgumentException if the buffer is null or is not a direct byte buffer.

        if ((directBuffer == null) || (!directBuffer.isDirect())) {
            throw new IllegalArgumentException();
        }
        DirectByteBuffer buf = (DirectByteBuffer) directBuffer;
        buf.free();
    
public static org.apache.harmony.luni.platform.PlatformAddressgetEffectiveAddress(java.nio.ByteBuffer directBuffer)
Returns the platform address of the start of this buffer instance. You must not attempt to free the returned address!! It may not be an address that was explicitly malloc'ed (i.e. if this buffer is the result of a split); and it may be memory shared by multiple buffers.

If you can guarantee that you want to free the underlying memory call the #free() method on this instance -- generally applications will rely on the garbage collector to autofree this memory.

param
directBuffer the direct byte buffer
return
the effective address of the start of the buffer.
throws
IllegalStateException if this buffer address is known to have been freed previously.

        return toDirectBuffer(directBuffer).getEffectiveAddress();
    
private static java.nio.DirectByteBuffertoDirectBuffer(java.nio.ByteBuffer directBuffer)

        if ((directBuffer == null) || (!directBuffer.isDirect())) {
            throw new IllegalArgumentException();
        }
        return (DirectByteBuffer) directBuffer;