|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.nps.moves.disutil.ByteBufferPool
public class ByteBufferPool
A pool that holds ByteBuffer objects.
We'd like to reuse buffers for sending, but this is tricky because the Java NIO byte buffers can't expand. So if we try to marshal a PDU that is 144 bytes long and one that is 800 bytes long, we'd always need a byte buffer that is 800 bytes long. This has some obvious problems if we generate 2000 byte buffer objects, which will have a big memory footprint that won't be GC'd. If this turns out to be a problem--I suspect not, right now--we can implement some sort of clear() operation to wipe out the pool once some criteria is met.
Instances of this class are defitnely not thread-safe. If you have two threads, you should have a ByteBufferPool for each thread to ensure that the same byte buffer from the pool isn't being used by two threads.
| Constructor Summary | |
|---|---|
ByteBufferPool()
|
|
| Method Summary | |
|---|---|
void |
clear()
Removes all the byte buffers from the pool, allowing them to be GC'd. |
java.nio.ByteBuffer |
getByteBufferOfLength(int length)
Returns a byte buffer from the pool that has the given length. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ByteBufferPool()
| Method Detail |
|---|
public java.nio.ByteBuffer getByteBufferOfLength(int length)
length -
public void clear()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||