Java Reference
In-Depth Information
public BufferPool(int poolsize, int defaultBufferSize) {
buffers = new byte[poolsize][];
this.defaultBufferSize = defaultBufferSize;
} public synchronized byte[] getBuffer() {
if ( count == 0 ) {
return new byte[defaultBufferSize];
} return buffers[--count];
} public synchronized void releaseBuffer(byte[] buffer)
if ( count == buffers.length ) {
return; // exceeds pool size, discard
} buffers[count++] = buffer;
If the pool is to be used by a single thread, you can remove the
synchronized keywords for slightly faster execution.
9.2.4 Use Images Efficiently
Images are essentially heavyweight objects that have the potential to use
large amounts of memory. There are two main practices for using images
in MIDlets efficiently: use the right format and resolution, and dispose of
unused images as soon as possible.
In general, most MIDP implementations provide support for the PNG
image format. The good thing about PNG format is that it is lossless
(i.e. no image information is lost during compression). This is great for
many use cases, for example, images with solid and contiguous colors
(such as, corporate logos and charts) or when transparency is required.
However, using PNG for photographic images or complex artwork is not
as efficient - image files tend to be large and take longer to load. For
such images, we can recommend JPEG format. They have a relatively
smaller heap footprint and file size, and are supported on all Symbian
OS devices supporting JTWI (see Chapter 2). PNG files are the minimum
supported by MIDP specification but, as most of the devices today are
JTWI-compliant, JPEG support is becoming widely available, especially
on Symbian OS devices.
Image resolution and color depth should be kept to the minimum
which allow the proper display of the image. For example, there's no
need for 24-bit color depth images if an 8-bit image provides satisfactory
results. Another point favoring the use of JPEG format is that some
platforms based on Symbian OS, such as S60, have hardware support for
it, making the decompression of JPEG images before viewing very fast
compared to PNG. A good place to learn more about JPEG and PNG file
formats is [Rutter 2003].
Search WWH ::

Custom Search