|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.partnersoft.v3x.io.BufferPool
public class BufferPool
This goober allows careful individuals a chance to optimize operations which require byte buffers by maintaining a pool of these buffers which are reused.
Caution must be exercised to prevent memory-related errors such as those prevalent to C/C++ environments - acquiring and releasing buffers is essentially the same as malloc() and free(), and reuse of a buffer once you have released it could cause all kinds of trouble - perhaps overwriting data at the same time as another object that has legitimately acquired the buffer.
In general, follow these rules:
The benefits should be fairly obvious - buffers are reused rather than garbage collected, reducing the amount of allocation and gc needed. This means that larger, more efficient buffers are practical. In a single-threaded system, only a few buffers will be allocated.
| Constructor Summary | |
|---|---|
BufferPool()
|
|
BufferPool(int bufferSize,
int maxBuffers)
|
|
| Method Summary | |
|---|---|
byte[] |
catchBuffer()
Grabs a buffer from the pool; allocates if necessary. |
int |
getBufferSize()
Size (int bytes) of buffers pooled. |
int |
getMaxBuffers()
Maximum number of buffers pooled. |
int |
getNumberOfBuffers()
Gets the current pool size. |
void |
releaseBuffer(byte[] buffer)
Releases a buffer back to the pool. |
void |
setBufferSize(int newSize)
Set buffer size. |
void |
setMaxBuffers(int newMax)
Set maximum number of buffers in pool. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BufferPool(int bufferSize,
int maxBuffers)
public BufferPool()
| Method Detail |
|---|
public int getBufferSize()
public void setBufferSize(int newSize)
public int getMaxBuffers()
public void setMaxBuffers(int newMax)
public int getNumberOfBuffers()
public byte[] catchBuffer()
public void releaseBuffer(byte[] buffer)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||