From 142c059031f42f1f4cb64873c634e655f3b7a46d Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Mon, 11 May 2009 10:26:10 +1000 Subject: Documentation patch from Jason A bunch of minor doc fixes. --- doc/src/examples/contiguouscache.qdoc | 34 ++++++++--------- src/corelib/tools/qcontiguouscache.cpp | 67 ++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/doc/src/examples/contiguouscache.qdoc b/doc/src/examples/contiguouscache.qdoc index 6c67d77..71e7740 100644 --- a/doc/src/examples/contiguouscache.qdoc +++ b/doc/src/examples/contiguouscache.qdoc @@ -44,11 +44,11 @@ \title Contiguous Cache Example The Contiguous Cache example shows how to use QContiguousCache to manage memory usage for - very large models. In some environments memory is limited, and even when it - isn't users still dislike an application using - excessive memory. Using QContiguousCache to manage a list rather than loading - the entire list into memory allows the application to limit the amount - of memory it uses regardless of the size of the data set it accesses + very large models. In some environments memory is limited and, even when it + isn't, users still dislike an application using excessive memory. + Using QContiguousCache to manage a list, rather than loading + the entire list into memory, allows the application to limit the amount + of memory it uses, regardless of the size of the data set it accesses The simplest way to use QContiguousCache is to cache as items are requested. When a view requests an item at row N it is also likely to ask for items at rows near @@ -56,7 +56,7 @@ \snippet examples/tools/contiguouscache/randomlistmodel.cpp 0 - After getting the row the class determines if the row is in the bounds + After getting the row, the class determines if the row is in the bounds of the contiguous cache's current range. It would have been equally valid to simply have the following code instead. @@ -68,13 +68,12 @@ \endcode However a list will often jump rows if the scroll bar is used directly, resulting in - the code above to cause every row between where the cache was last centered - to the requested row to be fetched before the requested row is fetched. + the code above causing every row between the old and new rows to be fetched. Using QContiguousCache::lastIndex() and QContiguousCache::firstIndex() allows - the example to determine where in the list the cache is currently over. These values - don't represent the indexes into the cache own memory, but rather a virtual - infinite array that the cache represents. + the example to determine what part of the list the cache is currently caching. + These values don't represent the indexes into the cache's own memory, but rather + a virtual infinite array that the cache represents. By using QContiguousCache::append() and QContiguousCache::prepend() the code ensures that items that may be still on the screen are not lost when the requested row @@ -84,16 +83,15 @@ rows with significant gaps between them consider using QCache instead. And thats it. A perfectly reasonable cache, using minimal memory for a very large - list. In this case the accessor for getting the words into cache: - - \snippet examples/tools/contiguouscache/randomlistmodel.cpp 1 - - Generates random information rather than fixed information. This allows you + list. In this case the accessor for getting the words into the cache + generates random information rather than fixed information. This allows you to see how the cache range is kept for a local number of rows when running the example. + \snippet examples/tools/contiguouscache/randomlistmodel.cpp 1 + It is also worth considering pre-fetching items into the cache outside of the - applications paint routine. This can be done either with a separate thread - or using a QTimer to incrementally expand the range of the thread prior to + application's paint routine. This can be done either with a separate thread + or using a QTimer to incrementally expand the range of the cache prior to rows being requested out of the current cache range. */ diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp index 1bcac96..95fa9e7 100644 --- a/src/corelib/tools/qcontiguouscache.cpp +++ b/src/corelib/tools/qcontiguouscache.cpp @@ -59,14 +59,14 @@ void QContiguousCacheData::dump() const \reentrant The QContiguousCache class provides an efficient way of caching items for - display in a user interface view. Unlike QCache though it adds a restriction - that elements within the cache are contiguous. This has the advantage that + display in a user interface view. Unlike QCache, it adds a restriction + that elements within the cache are contiguous. This has the advantage of matching how user interface views most commonly request data, as a set of rows localized around the current scrolled position. It also - allows the cache to use less overhead than QCache both in terms of - performance and memory. + allows the cache to consume less memory and processor cycles than QCache + for this use-case. - The simplest way of using an contiguous cache is to use the append() + The simplest way of using a contiguous cache is to use the append() and prepend(). \code @@ -82,18 +82,18 @@ MyRecord record(int row) const return cache.at(row); } \endcode - - If the cache is full then the item with the furthest index from where - the new item is appended or prepended is removed. + + If the cache is full then the item at the opposite end of the cache from where + the new item is appended or prepended will be removed. This usage can be further optimized by using the insert() function - in the case where the requested row is a long way from the currently cached - items. If there is a is a gap between where the new item is inserted and the currently + in the case where the requested row is a long way from the currently cached + items. If there is a gap between where the new item is inserted and the currently cached items then the existing cached items are first removed to retain the contiguous nature of the cache. Hence it is important to take some care then - when using insert() in order to avoid to unwanted clearing of the cache. + when using insert() in order to avoid unwanted clearing of the cache. - See the The \l{Contiguous Cache Example}{Contiguous Cache} example. + See the \l{Contiguous Cache Example}{Contiguous Cache} example. */ /*! \fn QContiguousCache::QContiguousCache(int capacity) @@ -116,6 +116,7 @@ MyRecord record(int row) const */ /*! \fn QContiguousCache::~QContiguousCache() + Destroys the cache. */ @@ -134,7 +135,6 @@ MyRecord record(int row) const \internal */ - /*! \fn QContiguousCache &QContiguousCache::operator=(const QContiguousCache &other) Assigns \a other to this cache and returns a reference to this cache. @@ -144,7 +144,7 @@ MyRecord record(int row) const Returns true if \a other is equal to this cache; otherwise returns false. - Two cache are considered equal if they contain the same values at the same + Two caches are considered equal if they contain the same values at the same indexes. This function requires the value type to implement the \c operator==(). \sa operator!=() @@ -155,17 +155,17 @@ MyRecord record(int row) const Returns true if \a other is not equal to this cache; otherwise returns false. - Two cache are considered equal if they contain the same values at the same + Two caches are considered equal if they contain the same values at the same indexes. This function requires the value type to implement the \c operator==(). \sa operator==() */ /*! \fn int QContiguousCache::capacity() const - + Returns the number of items the cache can store before it is full. When a cache contains a number of items equal to its capacity, adding new - items will cause items furthest from the added item to be removed. + items will cause items farthest from the added item to be removed. \sa setCapacity(), size() */ @@ -215,7 +215,7 @@ MyRecord record(int row) const Sets the capacity of the cache to the given \a size. A cache can hold a number of items equal to its capacity. When inserting, appending or prepending - items to the cache, if the cache is already full then the item furthest from + items to the cache, if the cache is already full then the item farthest from the added item will be removed. If the given \a size is smaller than the current count of items in the cache @@ -229,10 +229,10 @@ MyRecord record(int row) const Returns the item at index position \a i in the cache. \a i must be a valid index position in the cache (i.e, firstIndex() <= \a i <= lastIndex()). - The indexes in the cache refer to number of positions the item is from the + The indexes in the cache refer to the number of positions the item is from the first item appended into the cache. That is to say a cache with a capacity of 100, that has had 150 items appended will have a valid index range of - 50 to 149. This allows inserting an retrieving items into the cache based + 50 to 149. This allows inserting and retrieving items into the cache based on a theoretical infinite list \sa firstIndex(), lastIndex(), insert(), operator[]() @@ -283,10 +283,10 @@ MyRecord record(int row) const or a prepend(). If the given index \a i is not within the current range of the cache nor adjacent - to the bounds of the cache's index range the cache is first cleared before - inserting the item. At this point the cache will have a size of 1. It is worth - while then taking effort to insert items in an order that starts adjacent to the - current index range for the cache. + to the bounds of the cache's index range, the cache is first cleared before + inserting the item. At this point the cache will have a size of 1. It is + worthwhile taking effort to insert items in an order that starts adjacent + to the current index range for the cache. \sa prepend(), append(), isFull(), firstIndex(), lastIndex() */ @@ -299,6 +299,7 @@ MyRecord record(int row) const */ /*! \fn int QContiguousCache::firstIndex() const + Returns the first valid index in the cache. The index will be invalid if the cache is empty. However the following code is valid even when the cache is empty: @@ -350,7 +351,7 @@ MyRecord record(int row) const */ /*! \fn void QContiguousCache::removeFirst() - + Removes the first item from the cache. This function assumes that the cache isn't empty. @@ -358,7 +359,7 @@ MyRecord record(int row) const */ /*! \fn void QContiguousCache::removeLast() - + Removes the last item from the cache. This function assumes that the cache isn't empty. @@ -366,19 +367,21 @@ MyRecord record(int row) const */ /*! \fn T QContiguousCache::takeFirst() - - Removes the first item in the cache and returns it. - If you don't sue the return value, removeFirst() is more efficient. + Removes the first item in the cache and returns it. This function + assumes that the cache isn't empty. + + If you don't use the return value, removeFirst() is more efficient. \sa takeLast(), removeFirst() */ /*! \fn T QContiguousCache::takeLast() - - Removes the last item in the cache and returns it. - If you don't sue the return value, removeLast() is more efficient. + Removes the last item in the cache and returns it. This function + assumes that the cache isn't empty. + + If you don't use the return value, removeLast() is more efficient. \sa takeFirst(), removeLast() */ -- cgit v0.12