QCache Class ReferenceThe QCache class is a template class that provides a cache. More... #include <QCache> Note: All functions in this class are reentrant. Public Functions
Detailed DescriptionThe QCache class is a template class that provides a cache. QCache<Key, T> defines a cache that stores objects of type T associated with keys of type Key. For example, here's the definition of a cache that stores objects of type Employee associated with an integer key: QCache<int, Employee> cache; Here's how to insert an object in the cache: Employee *employee = new Employee; employee->setId(37); employee->setName("Richard Schmit"); ... cache.insert(employee->id(), employee); The advantage of using QCache over some other key-based data structure (such as QMap or QHash) is that QCache automatically takes ownership of the objects that are inserted into the cache and deletes them to make room for new objects, if necessary. When inserting an object into the cache, you can specify a cost, which should bear some approximate relationship to the amount of memory taken by the object. When the sum of all objects' costs (totalCost()) exceeds the cache's limit (maxCost()), QCache starts deleting objects in the cache to keep under the limit, starting with less recently accessed objects. By default, QCache's maxCost() is 100. You can specify a different value in the QCache constructor: QCache<int, MyDataStructure> cache(5000); Each time you call insert(), you can specify a cost as third argument (after the key and a pointer to the object to insert). After the call, the inserted object is owned by the QCache, which may delete it at any time to make room for other objects. To look up objects in the cache, use object() or operator[](). This function looks up an object by its key, and returns either a pointer to the cached object (which is owned by the cache) or 0. If you want to remove an object from the cache for a particular key, call remove(). This will also delete the object. If you want to remove an object from the cache without the QCache deleting it, use take(). See also QPixmapCache, QHash, and QMap. Member Function Documentation
|
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.8 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com