Class TTileStorage

Unit

Declaration

type TTileStorage = class(TObject)

Description

Class that encapsulates memory and file cache of tile images. It operates 3-level in-memory cache: TBitmap's, TPngImage's and TMemoryStream's. According to benchmarks, different actions take following percents of time:

Alas, each PNG occupies 3 GDI handles (on Windows) and each Bitmap takes about 250 kB of memory and 1 GDI handle. So we have to find balance between speed and resource consumption.

Hierarchy

Overview

Methods

Public constructor Create(CacheSize: Cardinal; const TilePathPatt: string = DefaultTilePathPatt); overload;
Public constructor Create(const CacheLimits: TCacheLimits; const TilePathPatt: string = DefaultTilePathPatt); overload;
Public destructor Destroy; override;
Public function GetTile(const Tile: TTile): TBitmap;
Public procedure StoreTile(const Tile: TTile; var Ms: TMemoryStream);
Public procedure ClearCache;

Properties

Public property Options: TTileStorageOptions read FOptions write FOptions;
Public property FileCacheBaseDir: string read FFileCacheBaseDir write SetFileCacheBaseDir;

Description

Methods

Public constructor Create(CacheSize: Cardinal; const TilePathPatt: string = DefaultTilePathPatt); overload;

Simplified constructor. Divides memory limit equally between bitmaps, PNGs and streams. Limits number of bitmaps and PNGs by GDI_HANDLES_LIMIT (on Windows)

Parameters
CacheSize
- overall size of all caches. Specific limits will be spread automatically.
TilePathPatt
- custom pattern of tile files' paths
Public constructor Create(const CacheLimits: TCacheLimits; const TilePathPatt: string = DefaultTilePathPatt); overload;

Constructor with detailed cache limits.

Parameters
CacheLimits
- record with detailed cache limits
TilePathPatt
- custom pattern of tile files' paths
Public destructor Destroy; override;

This item has no description.

Public function GetTile(const Tile: TTile): TBitmap;

Tries to get bitmap for Tile. If bitmap has been loaded from file, stores it in cache

Returns

Bitmap or Nil if not available locally

Public procedure StoreTile(const Tile: TTile; var Ms: TMemoryStream);

Adds memory stream Ms, PNG and bitmap produced from it to memory and file cache.
! TileStorage takes ownership on Ms so caller should forget about it !

Parameters
Tile
- tile to store
Ms
- memory stream containing PNG image. When function returns, this reference gets nulled even if an exception has risen.
Exceptions raised
Exception
if Ms doesn't contain valid PNG data
Public procedure ClearCache;

Empty all caches

Properties

Public property Options: TTileStorageOptions read FOptions write FOptions;

Storage options

Public property FileCacheBaseDir: string read FFileCacheBaseDir write SetFileCacheBaseDir;

Base directory of file cache. All cached images are released on path change


Generated by PasDoc 0.16.0.