Memory Storage Types for Images

Conventional images: The most common images - support all bits/pixel and with the fastest access time. But they also require the highest amount of memory.

Compressed images: 1-bit only, using a proprietary RLE compression. They usually require less memory than the conventional images.

Super-Compressed images: 1-bit (uses Fax G4 compression) or 24-bit (uses MCMP compression) only. They require little memory but the read and write operations performed on the image are slower. Also, the 24-bit compression is lossy, which means there is some small amount of degradation each the 24-bit super-compressed image changes. (The 1-bit super-compressed image uses lossy compression, so there is never any quality loss).

Disk images: all the image data is on disk. But a memory view is used to access the disk, which causes more and more conventional memory to be used as you read or write more image pixels.

Tiled images: the image is broken into separate tiles. Tiles can be disk or conventional memory.

You can specify the type of image you want when you create a new RasterImage instance. LEADTOOLS to react dynamically depending on the image size or the amount of available memory using the RasterMemoryThreshold structure.

When LEADTOOLS has to allocate a conventional image, it does the following:

1.

If the size of the image being allocated is less than the fixed tile size (set through the RasterMemoryThreshold structure when uTileSize is > 0), the image is allocated as conventional. If the allocation fails, the memory allocation method fails. If the allocation succeeds, the memory allocation method returns SUCCESS. No other steps are executed.

2.

Checks the maximum size for a conventional image (set through the RasterMemoryThreshold structure). If the size of the image being allocated is greater than this threshold, a tiled image will be allocated. Go to step 5. If the size of the image being allocated is lower than the threshold, go to step 3.

3.

Checks whether there is enough available memory to allocate a conventional image. (This threshold is also set through the RasterMemoryThreshold structure). If there is not enough free memory, a tiled image will be allocated and go to step 5. Else, go to step 4.

4.

Try to allocate a conventional memory image (image which is contained entirely in conventional memory. If the allocation succeeds, the memory allocation returns success and no other steps are performed. If the allocation fails, go to step 5.

5.

Try to allocate a tiled image. There can be a mix of disk and conventional memory tiles. If the method succeeds, the allocation method returns success and no other steps are performed. If the allocation fails, go to step 6.

By default, the Windows temporary directory is used to store the disk files used for the disk tiles and disk images. You can change the location where these files are stored and you can get the current location using the TemporaryDirectory property

MemoryFlags can only be set to RasterMemoryFlags.Conventional or RasterMemoryFlags.Disk when setting defaults.

Even when you have lots of RAM and enough space in the swap file, Windows might fail to allocate you one contiguous chunk of conventional memory. In this case, the image will be allocated as tiled or disk.

Example: You attempt to allocate a 512 MB image. Windows might fail to allocate a contiguous 512 MB memory chunk, but it might be able to allocate you 2x 256 MB chunks or 4x 128 MB chunks. In this case, LEADTOOLS allocates your 512 MB image using several smaller chunks in a tiled image.

In a more extreme case, you might have not enough space to allocate the whole image in conventional memory. Or you might have specified a maximum amount of conventional memory to be used with an image. In either of these cases, LEADTOOLS will try to allocate a tiled image with some tiles in conventional memory and others on disk.

The conventional memory tiles are always accessible (read further to see why this matters). Disk tiles will still need some chunks of conventional memory to read from disk/write to disk. We will refer to these chunks as "views". The more views you have, the more disk tiles can be accessed at a time and the faster the working with the image will be. When you read or read from a disk tile, data is being cached to the view and no disk access is performed unless you move to another tile. The "move to another tile" operation is performed automatically when you read or write data to a certain row.

When you go to a disk tile that has no view, LEADTOOLS will:

create a new "view" (if you have not exceeded the maximum allowed of views and you have available memory) or

discard an old view and reassign it to the new tile. When the old view is discarded, data is written to the disk (if it has been modified since it was read). The writing of data to disk will cause a performance hit.

You can find out the memory allocation parameters for an image or change the memory allocation parameters using MemoryInformation. The memory information consists of:

The memory type (conv, tiled, disk, etc)

These are for tiled images only:

The number of tiles

The tile size

The number of tiles in conventional memory

The maximum number of tile views in the conventional memory (for disk tiles only)

The number of tile views in the conventional memory (for disk tiles only)