Class TVideosCache
Unit
CastleVideos
Declaration
type TVideosCache = class(TObject)
Description
A cache of loaded videos.
The idea is that instead of creating TVideo instance and calling TVideo.LoadFromFile, you instead call Video := Cache.Video_IncReference(...) . Later, instead of freeing this video, call Video_DecReference(Video) . From your point of view, things will work the same. But if you expect to load many videos from the same URL, then you will get a great speed and memory saving, because video will only be actually loaded once. This may happen e.g. if you have a VRML / X3D file with lots of MovieTexture nodes with the same urls.
Notes:
Note that before destroying this object you must free all videos, i.e. call Video_DecReference for all videos allocated by Video_IncReference. This class is not a lousy way of avoiding memory leaks — it would be a bad idea, because it would cause sloppy programming, where memory is unnecessarily allocated for a long time. In fact, this class asserts in destructor that no videos are in cache anymore, so if you compiled with assertions enabled, this class does the job of memory-leak detector.
Hierarchy
Overview
Methods
Properties
 |
property OnEmpty: TProcedure read FOnEmpty write FOnEmpty; |
Description
Methods
 |
procedure CheckEmpty; |
If cache is empty, calls OnEmpty. Note that OnEmpty may destroy current instance, so call CheckEmpty only when you finished processing — Self may be invalid afterwards.
|
 |
constructor Create; |
|
 |
destructor Destroy; override; |
|
 |
procedure Video_DecReference(var Video: TVideo); |
|
 |
function Empty: boolean; virtual; |
|
Properties
 |
property OnEmpty: TProcedure read FOnEmpty write FOnEmpty; |
Called when cache becomes empty. This is only for internal usage by X3DNodes unit for now.
|
Generated by PasDoc 0.13.0 on 2014-08-30 12:10:43
|