Class TVideosCache

Unit

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

  • TObject
  • TVideosCache

Overview

Methods

Protected procedure CheckEmpty;
Public constructor Create;
Public destructor Destroy; override;
Public function Video_IncReference(const Url: String; out AlphaChannel: TAlphaChannel; const LoadOptions: TLoadImageOptions = []): TVideo;
Public procedure Video_DecReference(var Video: TVideo);
Public function Empty: boolean; virtual;

Properties

Public property OnEmpty: TProcedure read FOnEmpty write FOnEmpty;

Description

Methods

Protected 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.

Public constructor Create;

This item has no description.

Public destructor Destroy; override;

This item has no description.

Public function Video_IncReference(const Url: String; out AlphaChannel: TAlphaChannel; const LoadOptions: TLoadImageOptions = []): TVideo;

This item has no description.

Public procedure Video_DecReference(var Video: TVideo);

This item has no description.

Public function Empty: boolean; virtual;

This item has no description.

Properties

Public 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.16.0-snapshot.