de.netseeker.ejoe.cache
Class ByteBufferAllocator

java.lang.Object
  extended by de.netseeker.ejoe.cache.ByteBufferAllocator

public class ByteBufferAllocator
extends java.lang.Object

Utility supporting safe allocations and caching of ByteBuffers.

Since:
0.4.0
Author:
netseeker

Constructor Summary
ByteBufferAllocator()
           
 
Method Summary
static java.nio.ByteBuffer allocate(int size)
          Allocates either a direct or a indirect ByteBuffer.
static java.nio.ByteBuffer allocate(int size, boolean direct)
          Allocates either a direct or a indirect ByteBuffer.
static void collect(java.nio.ByteBuffer buffer)
          Tries to clear and destroy a existing ByteBuffer
static java.nio.ByteBuffer reAllocate(java.nio.ByteBuffer src, int newSize)
          Resizes a given ByteBuffer to a new size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteBufferAllocator

public ByteBufferAllocator()
Method Detail

allocate

public static java.nio.ByteBuffer allocate(int size,
                                           boolean direct)
Allocates either a direct or a indirect ByteBuffer. If a indirect ByteBuffer was requested but could not be allocated because lack of free java heap, a direct ByteBuffer will be allocated and returned

Parameters:
size - target size of the requested new ByteBuffer
direct -
Returns:
either a direct or an indirect ByteBuffer depending on request and memory state

allocate

public static java.nio.ByteBuffer allocate(int size)
Allocates either a direct or a indirect ByteBuffer. This method decides automatically if a direct or indirect ByteBuffer should be allocated.

Parameters:
size - target size of the requested new ByteBuffer
size -
Returns:
either a direct or an indirect ByteBuffer depending on target size and memory state

reAllocate

public static java.nio.ByteBuffer reAllocate(java.nio.ByteBuffer src,
                                             int newSize)
Resizes a given ByteBuffer to a new size.

Parameters:
src - ByteBuffer to get resized
newSize - size in bytes for the resized buffer

collect

public static void collect(java.nio.ByteBuffer buffer)
Tries to clear and destroy a existing ByteBuffer

Parameters:
buffer -


Copyright © 2005-2007 netseeker. All Rights Reserved.