Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  chap5.html   Sprache: HTML

 
 products/Sources/formale Sprachen/GAP/pkg/orb/doc/chap5.html


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (orb) - Chapter 5: Caching techniques</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap5"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop"> <a href="chap0.html">[Top of Book]</a>   <a href="chap0.html#contents">[Contents]</a>    <a href="chap4.html">[Previous Chapter]</a>    <a href="chap6.html">[Next Chapter]</a>   </div>

<p id="mathjaxlink" class="pcenter"><a href="chap5_mj.html">[MathJax on]</a></p>
<p><a id="X86BA72E27E278718" name="X86BA72E27E278718"></a></p>
<div class="ChapSects"><a href="chap5.html#X86BA72E27E278718">5 <span class="Heading">Caching techniques</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap5.html#X87639FAC8621A75A">5.1 <span class="Heading">The idea of caching</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap5.html#X7B269D167B6C9BF6">5.2 <span class="Heading">Using caches</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap5.html#X7FF40AE981FE6F75">5.2-1 LinkedListCache</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap5.html#X7ECBA1228365BDC4">5.2-2 CacheObject</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap5.html#X7E1D239886BC762C">5.2-3 ClearCache</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap5.html#X819FD13C7CCC6810">5.2-4 UseCacheObject</a></span>
</div></div>
</div>

<h3>5 <span class="Heading">Caching techniques</span></h3>

<p><a id="X87639FAC8621A75A" name="X87639FAC8621A75A"></a></p>

<h4>5.1 <span class="Heading">The idea of caching</span></h4>

<p>If one wants to work with a large number of large objects which require some time to prepare and one does not know beforehand, how often one will need each one, it makes sense to work with some sort of cache. A cache is a data structure to keep some of the objects already produced but not too many of them to waste a lot of memory. That is, objects which have not been used for some time can automatically be removed from the cache, whereas the objects which are used more frequently stay in the cache. This chapter describes an implementation of this idea used in the orbit-by-suborbit algorithms.</p>

<p><a id="X7B269D167B6C9BF6" name="X7B269D167B6C9BF6"></a></p>

<h4>5.2 <span class="Heading">Using caches</span></h4>

<p>A cache is created using the following operation:</p>

<p><a id="X7FF40AE981FE6F75" name="X7FF40AE981FE6F75"></a></p>

<h5>5.2-1 LinkedListCache</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ LinkedListCache</code>( <var class="Arg">memorylimit</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Returns: A new cache object</p>

<p>This operation creates a new linked list cache that uses at most <var class="Arg">memorylimit</var> bytes to store its entries. The cache is organised as a linked list, newly cached objects are appended at the beginning of the list, when the used memory grows over the limit, old objects are removed at the end of this list automatically.</p>

<p>New objects are entered into the hash with the following function:</p>

<p><a id="X7ECBA1228365BDC4" name="X7ECBA1228365BDC4"></a></p>

<h5>5.2-2 CacheObject</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CacheObject</code>( <var class="Arg">c</var>, <var class="Arg">ob</var>, <var class="Arg">mem</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Returns: A new node in the linked list cache</p>

<p>This operation enters the object <var class="Arg">ob</var> into the cache <var class="Arg">c</var>. The argument <var class="Arg">mem</var> is an integer with the memory usage of the object <var class="Arg">ob</var>. The object is prepended to the linked list cache and enough objects at the end are removed to enforce the memory usage limit.</p>

<p><a id="X7E1D239886BC762C" name="X7E1D239886BC762C"></a></p>

<h5>5.2-3 ClearCache</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ClearCache</code>( <var class="Arg">c</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Returns: Nothing</p>

<p>Completely clears the cache <var class="Arg">c</var> removing all nodes.</p>

<p>A linked list cache is used as follows: Whenever you compute one of the objects you store it in the cache using <code class="func">CacheObject</code> (<a href="chap5.html#X7ECBA1228365BDC4"><span class="RefLink">5.2-2</span></a>) and retain the linked list node that is returned. The usual place to retain it would be in a weak pointer object, such that this reference does not prevent the object to be garbage collected. When you next need this object, you check its corresponding position in the weak pointer object, if the reference is still there, you just use it and tell the cache that it was used again by calling <code class="func">UseCacheObject</code> (<a href="chap5.html#X819FD13C7CCC6810"><span class="RefLink">5.2-4</span></a>), otherwise you create it anew and store it in the cache again.</p>

<p>As long as the object stays in the cache it is not garbage collected and the weak pointer object will still have its reference. As soon as the object is thrown out of the cache, the only reference to its node is the weak pointer object, thus if a garbage collection happens, it can be garbage collected. Note that before that garbage collection happens, the object might still be accessible via the weak pointer object. In this way, the available main memory in the workspace is used very efficiently and can be freed immediately when needed.</p>

<p><a id="X819FD13C7CCC6810" name="X819FD13C7CCC6810"></a></p>

<h5>5.2-4 UseCacheObject</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ UseCacheObject</code>( <var class="Arg">c</var>, <var class="Arg">r</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Returns: Nothing</p>

<p>The argument <var class="Arg">c</var> must be a cache object and <var class="Arg">r</var> a node for such a cache. The object is either moved to the front of the linked list (if it is still in the cache) or it is re-cached. If necessary, objects at the end are removed from the cache to enforce the memory usage limit.</p>


<div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a>   <a href="chap0.html#contents">[Contents]</a>    <a href="chap4.html">[Previous Chapter]</a>    <a href="chap6.html">[Next Chapter]</a>   </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>

100%


¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge