Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand correctly, you're asking why someone might implement a cache as</p> <pre><code>void DoSomethingWith(CGColorRef c) { static CGColorRef cached_c = NULL; static CFTypeID cached_colorID; if (c == cached_c &amp;&amp; c-&gt;colorID == cached_colorID) ... </code></pre> <p>instead of merely</p> <pre><code>void DoSomethingWith(CGColorRef c) { static CFTypeID cached_colorID = 0; if (c-&gt;colorID == cached_colorID) ... </code></pre> <p>? Well, two obvious reasons are</p> <ul> <li><p><a href="http://highscalability.com/blog/2013/6/13/busting-4-modern-hardware-myths-are-memory-hdds-and-ssds-rea.html" rel="nofollow">Random access memory isn't random access.</a> Dereferencing <code>c</code> is probably a slow operation (a cache miss wastes many nanoseconds), so if we can save those nanoseconds 90% of the time by prepending a cheap pointer comparison, let's do it.</p></li> <li><p>How do you initialize <code>cached_colorID</code>? In the first implementation above, if we assume that the user respects the API contract and always passes in a non-null <code>c</code>, then once we know <code>c</code> == <code>cached_c</code>, then we also know that <code>cached_c != NULL</code> and therefore we have a meaningful value in <code>cached_colorID</code>. In the second implementation, if the first <code>c</code> the user passes in happens to have <code>c-&gt;colorID == 0</code>, then we'll incorrectly believe that we've seen it before, and madcap hijinks ensue.</p></li> </ul> <p>I don't know if either of these is the reason Apple did what you're looking at... but they seem like solid possibilities, don't they?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload