|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jnetpcap.nio.JMemoryPool
public class JMemoryPool
Provides a mechanism for allocating memory to JMemory objects. This class is intended to be used when for example JPacket objects need to be kept around for longer periods of time than a single loop cycle. Since libpcap library utilizes a round-robin memory buffer for returning packet data buffers, this class provides a mechanism for copying that data into more permanent storage very efficiently.
The pool works by allocating a memory blocks which are given out to any JMemory class that requests a chunk. That memory is given out, out of the pool, until the block is completely exhausted, then a new block is allocated and continues to give out the memory. The memory blocks are released and deallocated when the last JMemory block that receive any of the memory is garbage collected. When that happens the original memory block is deallocated with a native C free() call. The user does not have to do anything special, the memory management is done completely behind the scene, very efficiently and automatically using.
| Nested Class Summary | |
|---|---|
static class |
JMemoryPool.Block
A block of native memory allocated with malloc. |
| Field Summary | |
|---|---|
static int |
DEFAULT_BLOCK_SIZE
Default block size. |
| Constructor Summary | |
|---|---|
JMemoryPool()
Uses default allocation size and strategy. |
|
JMemoryPool(int defaultBlockSize)
Allocates blocks in specified size |
|
| Method Summary | |
|---|---|
void |
allocate(int size,
JMemory memory)
Allocates size bytes of memroy and initializes the supplied memory pointer class. |
static JBuffer |
buffer(int size)
|
JMemoryPool.Block |
getBlock(int size)
Gets a block of memory that is big enough to hold at least size number of bytes. |
static void |
malloc(int size,
JMemory storage)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_BLOCK_SIZE
| Constructor Detail |
|---|
public JMemoryPool()
public JMemoryPool(int defaultBlockSize)
defaultBlockSize - minimum memory block allocation size| Method Detail |
|---|
public JMemoryPool.Block getBlock(int size)
JMemoryPool.Block.allocate(int) the size of memory needed. The block will then
return an offset into the memory which has been reserved for this
allocation
size - minimum available amount of memory in a block
JMemoryPool.Block.allocate(int)
public void allocate(int size,
JMemory memory)
size - number of bytesmemory - memory pointer
public static void malloc(int size,
JMemory storage)
size - storage - public static JBuffer buffer(int size)
size - storage -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||