Image Cache

<< Click to Display Table of Contents >>

Navigation:  Programming Techniques > Pictures >

Image Cache

Previous pageReturn to chapter overviewNext page

To increase performance, VPE has a build-in dynamic image cache.

(Note: the Community Edition has no image cache)

VPE manages images in an intelligent cache, so that the most frequently used images are held in memory. VPE holds as much images in memory as possible, restricted by the property PictureCacheSize. If an image fell out of the cache and it is required again (i.e. an image is displayed or printed), VPE loads the image with high performance back into the cache.

The cache guarantees maximum performance, whilst allowing the import of an unlimited number of images into a document. The cache is per process, i.e. it is shared between all documents / threads of a single process, but it is not shared between different processes.

Set the property PictureCache = true (this is the default) to move images into the dynamic cache area. This only works for pictures inserted by filename (not for resources or DIB's). Each calling application has its own cache, but the cache is shared by all open documents of one application. Images are also held in the cache when a document is closed. The cache memory is only freed when VPE is unloaded from memory, i.e. when your application terminates.

We recommend to set PictureCache = true always.

If you set it to false, an image is loaded into memory each time it is displayed, printed or exported (for example to PDF).

 

By default, the image cache is 64 MB in size. You can set the cache size with:

DLL:VpeSetPictureCacheSize( <KB> )
Control:PictureCacheSize = <KB>
where <KB> is the size of the cache in kilobytes.

Example:        

PictureCacheSize = 4096

sets the cache size to 4 megabytes

 

The cache can be flushed (emptied) by the following sequence:

old_value = PictureCacheSize

PictureCacheSize = 0

PictureCacheSize = old_value

 

The size of the picture cache is a virtual size. That means VPE does not reserve memory for the cache in advance. Instead, if a picture is read into memory VPE will reserve as much memory as needed to hold the image in memory. If the amount of memory needed for all cached images together becomes bigger than the specified image cache size, VPE will remove as much images from memory that were accessed less often, until there is enough space to keep the newly read image in memory.

Therefore, VPE will keep at least the last read image in the cache, even if it is larger than the maximum possible cache size.

 

Example:

PictureCacheSize = 4096

Image cache is 4 MB now

 

Picture(1, 1, VFREE, VFREE, "image1.tif")

Image1 is read into memory, it needs 2 MB and is cached.

 

Picture(1, 1, VFREE, VFREE, "image2.jpg")

Image2 is read into memory, it needs 1 MB and is also cached. Now 3 MB of the cache are used.

 

Picture(1, 1, VFREE, VFREE, "image2.tif")

Image1 is taken from the cache without loss of performance

 

Picture(1, 1, VFREE, VFREE, "image3.bmp")

Image3 is read into memory, it needs 1.5 MB. Because the cache is not large enough to store it also in the cache, the least frequent used image is removed from the cache. This is "image2.jpg". Now 3.5 MB of the cache are used (2MB for image1 and 1.5 MB for image3).

 

Picture(1, 1, VFREE, VFREE, "image2.tif")

Image1 is still taken from the cache without loss of performance

 

NOTE:In fact VPE has a multi-level associative cache and on the top-level it stores meta information about images (for example type, width, height and resolution) together with their path- and file names. This top-level cache can not be flushed. It removes itself entries when an internally hardcoded threshold-value is reached. On the low level the cache stores the binary image data, i.e. the bitmap data, which is deleted when flushing the cache.
 
The cache has some implications for the design of your application: since the cache only holds as much binary image data (i.e. the bitmap data) in memory, as allowed by the cache size, VPE might load at any time image files from disk as desired.
Therefore you may not delete or overwrite image files, which are currently used in any open document of your application.
 
It must also be noted that the cache of VPE is still active, after you have closed a VPE document. This makes sense, because if you create another VPE document which uses the same images (for example company logos), they can be used extremely fast. The whole cache – including the top-level cache – is only deleted from memory, after your application has terminated.
 
If an image file is not used within any open document of the same process, you can safely delete or overwrite it.