org.objectweb.jonathan.resources.lib

Class JChunkFactory

Implemented Interfaces:
ChunkFactory

public class JChunkFactory
extends Object
implements ChunkFactory

A Chunk Factory implementation.

A chunk factory creates and manages chunks. This chunk factory manages two pools of chunks of different sizes, so that a released chunk may be reused in a different context, saving the time for allocating and collecting the associated memory. The sizes of the chunks used, and of the preallocated pools may be changed.

Field Summary

boolean
verbose
Indicates whether warning message should be printed to stderr.

Constructor Summary

JChunkFactory()
Returns a new chunk factory
JChunkFactory(int big_pool_size, int big_size, int small_pool_size, int small_size, boolean verbose)
Returns a new chunk factory

Method Summary

Chunk
newChunk()
Returns a chunk of a default (small) size.
Chunk
newChunk(int size)
Returns a chunk of (at least) the specified size.

Field Details

verbose

public boolean verbose
Indicates whether warning message should be printed to stderr.

In particular, if verbose is true, and if all the chunks in a pool are used, a warning will be emitted. This may be useful to tune the pool sizes.

This value is defined under the name "/jonathan/JChunkFactory/verbose" in the bootstrap context.

Constructor Details

JChunkFactory

public JChunkFactory()
Returns a new chunk factory


JChunkFactory

public JChunkFactory(int big_pool_size,
                     int big_size,
                     int small_pool_size,
                     int small_size,
                     boolean verbose)
Returns a new chunk factory

Parameters:
big_pool_size - size of the big chunks pool
big_size - size of the big chunks
small_pool_size - size of the small chunks pool
small_size - size of the small chunks
verbose - indicates whether warning messages should be printed to stderr.

See Also:
verbose

Method Details

newChunk

public Chunk newChunk()
Returns a chunk of a default (small) size.
Specified by:
newChunk in interface ChunkFactory

Returns:
a chunk


newChunk

public Chunk newChunk(int size)
Returns a chunk of (at least) the specified size.

This method may return a larger chunk than expected.

Specified by:
newChunk in interface ChunkFactory

Parameters:
size - the expected size of the chunk.

Returns:
a chunk