Into

Modules

Documentation

classPiiCacheOperation

#include <PiiCacheOperation.h>

An operation that caches processing results.

Inherits PiiDefaultOperation

Description

PiiCacheOperation can be used to avoid recalculating values that need to be used more than once. The most typical use is in caching feature vectors used for training a classifier.

The implementation of this operation is still incomplete. Don't use.

The cache works by associating each cached object with a key. Whenever a key is received, the cache is searched for an occurrence. If a hit is found, it will be sent to the data output. If not, the key will be passed to the key output. The found output will emit either 0 or 1 depending on the search result (0 = not found, 1 = found).

The cache must be connected so that if an object is not found, a new object will always be received in the data input. This usually means a loop-back connection wired to the key output; whenever a key is emitted, it causes the calculation of a new object that will be sent back to the cache to be associated with the key.

Inputs

keya cache key that uniquely identifies data in the cache. A QString or a primitive type that is convertible to a QString.
datathe data associated with key. Any type. Note that this input is not synchronous to key. It must receive an object if and only if the key output emits an object. Objects in this input will be passed directly to the data output.

Outputs

found0 or 1 depending on whether the key was found in cache or not (0 = not found, 1 = found). This output can be used as a control signal to a PiiDemuxOperation.
keypasses the object in the key input, if the key was not found in cache.
datathe data associated with the key input, if found in the cache. In the case of a cache miss, an object received in the data input will be passed to this output.

Properties

bool

Allow/disallow changing of object emission order.

int

The maximum number of bytes the cache is allowed to occupy.

int

The maximum number of objects the cache is allowed to hold.

Constructors and destructor

Public member functions

bool
int
int
void
(
  • bool allowOrderChanges
)
void
(
  • int maxBytes
)
void
(
  • int maxObjects
)

Protected member functions

virtual void

Executes one round of processing.

Property details

  • bool allowOrderChanges

    [read, write]

    Allow/disallow changing of object emission order.

    If an object is found in the cache, it could be sent to the data output right away. Normally, this is however not done until all data related to previously received requests has been handled to avoid synchronization problems. If it doesn't matter in which order the objects are sent, setting this flag to true may increase processing speed on multi-core machines.

  • int maxBytes

    [read, write]

    The maximum number of bytes the cache is allowed to occupy.

    The operation recognizes all primitive types, complex numbers, and matrices composed of them. It also knows QStrings. The number of bytes an object occupies is an approximation because memory allocation techniques vary. The operation uses an estimate of 32 bytes per each object (const PiiVariant&). If the object is a primitive type, additional 32 bytes will be assumed. If it is a matrix, 32 bytes + sizeof(T) * rows * columns will be assumed. The size of a QString is assumed to be 32 + two times its length. Zero means no limit. The default is 2 Mb.

  • int maxObjects

    [read, write]

    The maximum number of objects the cache is allowed to hold.

    Zero (the default) means no limit.

Function details

  • PiiCacheOperation

    ()
  • bool allowOrderChanges

    ()
  • int maxBytes

    ()
  • int maxObjects

    ()
  • void setAllowOrderChanges

    (
    • bool allowOrderChanges
    )
  • void setMaxBytes

    (
    • int maxBytes
    )
  • void setMaxObjects

    (
    • int maxObjects
    )
  • virtual void process

    ()
    [protected, virtual]

    Executes one round of processing.

    This function is invoked by the processor if the necessary preconditions for a new processing round are met. This function does all the necessary calculations to create output objects and sends them to output sockets.

    Calls to process(), syncEvent(), and setProperty() are synchronized and cannot occur simultaneously. PiiDefaultOperation ensures this by locking processLock() for reading before calling process().

    Note: With time-consuming operations, one should occasionally check that the operation hasn't been interrupted, i.e. that state() returns Running.

    Exceptions
    PiiExecutionException

    whenever an unrecoverable error occurs during a processing round, the operation is interrupted, or finishes execution due to end of input data.

    Reimplemented from PiiDefaultOperation.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.