java.lang.Object
edu.emory.mathcs.util.allocator.PoolingAllocator
- All Implemented Interfaces:
- Allocator
- public class PoolingAllocator
- extends java.lang.Object
- implements Allocator
Implements the Allocator using memory buffer pool. Able to enforce
memory usage limits; attempts to avoid OutOfMemoryErrors by postponing the
allocate requests when there is insufficient memory available in the system.
Parameters of the pool are: (1) reserved capacity --
if the current memory usage of the pool is below this value, the allocate
request will be always attempted without blocking; (2) maximum capacity --
if the allocate request would inflate the current memory usage above this
value, the call will block until more memory is available; (3) security
margin -- if the memory available in the system is below this value, the
allocate request will block unless current usage is below reserved capacity.
- Version:
- 1.0
Constructor Summary |
PoolingAllocator()
Constructs pooling allocator with default reserved capacity of
1 MB, unlimited maximum capacity and default security margin
of 2 MB. |
PoolingAllocator(long reserved,
long max)
Constructs pooling allocator with specified reserved and maximum capacity
and default security margin of 2 MB. |
PoolingAllocator(long reserved,
long max,
int minLeft)
Constructs pooling allocator with specified reserved and maximum capacity
and specified security margin. |
PoolingAllocator(long reserved,
long max,
int minLeft,
BufferPool bufpool)
Constructs pooling allocator with specified reserved and maximum capacity
and specified security margin, as well as given buffer pool. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
bufpool
final BufferPool bufpool
runtime
private final java.lang.Runtime runtime
reserved
private final long reserved
max
private final long max
minLeft
private final long minLeft
memOccupied
private long memOccupied
lastFreeMem
private long lastFreeMem
occupiedOnLastFreeMem
private long occupiedOnLastFreeMem
PoolingAllocator
public PoolingAllocator()
- Constructs pooling allocator with default reserved capacity of
1 MB, unlimited maximum capacity and default security margin
of 2 MB.
PoolingAllocator
public PoolingAllocator(long reserved,
long max)
- Constructs pooling allocator with specified reserved and maximum capacity
and default security margin of 2 MB.
PoolingAllocator
public PoolingAllocator(long reserved,
long max,
int minLeft)
- Constructs pooling allocator with specified reserved and maximum capacity
and specified security margin.
PoolingAllocator
public PoolingAllocator(long reserved,
long max,
int minLeft,
BufferPool bufpool)
- Constructs pooling allocator with specified reserved and maximum capacity
and specified security margin, as well as given buffer pool.
allocate
public Allocator.Buffer allocate(int size,
boolean clear,
long timeout)
throws java.lang.InterruptedException
- Description copied from interface:
Allocator
- Allocate a buffer with specified size. The operation can
block if memory limits are exceeded. The timeout value greater
than 0 indicates the timeout, the value of 0 will cause immediate
return of null if the buffer was not available, and value less
than zero will cause to wait for buffer inidefinitely. The
clear parameter indicates that the buffer should be zeroed out.
Since buffers may be recycled, the buffer returned may contain random
garbage if this value is false. If it is set to true, the [0..size]
region of the array within the buffer is filled with zeros.
This method may return a buffer containing an array larger than
requested.
- Specified by:
allocate
in interface Allocator
canAlloc
private boolean canAlloc(int size)
reclaim
private void reclaim(byte[] data)