You are here: Object Cache Management
MtxVec VCL
ContentsIndex
PreviousUpNext
Object Cache Management

In order to reduce the number of: Object create/destroy and GetMem/FreeMem calls, the MtxVec unit uses object cache. Object cache forms an array of precreated objects of two types: TVec and TMtx. Other types are not supported. The user can obtain a pointer to an object from this array by calling CreateIt procedure. To release the reserved object you should call FreeIt procedure. This approach allows the user to precreate a relatively small amount of objects (16), taking up about 100kB of memory, and avoid continuous creation and destruction of objects. 

The object cache reduces the amount of calls for memory allocation and deallocation for small arrays, because each bject has a small amount of preallocated memory. The amount of preallocated memory is defined by a property: Controller.MtxCacheElements for TMtx and Controller.VecCacheElements for TVec. They both define the amount of memory as the number of TSample elements. If object cache runs out of objects at some point, the Controller.MtxCacheFull (Controller.VecCacheFull ) flags are set to True, and the requested object is created as usually. You can check Controller.MtxCacheFull property to see, if the size the Mtx object cache was to small to handle all requests. If the size of the object exceeds the already allocated memory, new memory is allocated. When the object is freed (With FreeIt method), if it is a member of the object cache and more memory was allocated, that memory is deallocated and the memory pointer is again pointed back to the preallocated memory. Memory preallocation can be turned off by calling the Controller.SetMtxCacheSize method with Elements parameter set to zero. 

TMtxVec object has a property: ActualSize. This property shows the actual amount of elements allocated for the object. 

The property Controller.MtxCacheUsed (Controller.VecCacheUsed) contains the number of matrices currently used in the matrix cache. That property can not be set. The size of the cache is set by the call to Controller.SetMtxCacheSize (Controller.SetVecCacheSize) method. Call this procedure before you create any TMtx (TVec) objects.By default, when the program starts the following commands are executed: 

 

SetVecCacheSize(32, 1024); // create 32 vector objects with 1024 elements each SetMtxCacheSize(16, 32); //create 16 matrix objects with 32x32 elements each

 

This preallocates sufficient resources to allow optimal MtxVec performance in most cases.

Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!