Pointers: not just for xmas

File this under the category of “handy coding hints”…

With the disparity between CPU performance, the benefits of CPU-cache memory and system RAM, it’s not always best to retain large caches of relatively trivial generatable data – a histogram of the last 3-4 entries might be all you need especially if you can very cheaply keep them ordered so that if 1 in 3 calls produces the same result, that result will be handy.

On the other hand, a cache might be useful if you have a comparatively small result set but a lot of users of the same results. You could then give out pointers to the result sets so that when the data changes you only have to update the cache and everyone’s effective data changes immediately. That could be quite the saving.

Just keep in mind that you gave out pointers a few minutes later when you write code that periodically expires said data. And more important still, if a few minutes later you write some code that periodically clears out the cache and rebuilds it, don’t act all surprised when the data you were pointing to seems to keep going away…

Boy do I feel like an idiot :) At least my brain caught up with me before I ever tried to actually run the thing :)

One Comment

It is friday the 13th ;)

Leave a Reply

Name and email address are required. Your email address will not be published.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

You may use these HTML tags and attributes:

<a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <pre> <q cite=""> <s> <strike> <strong> 

%d bloggers like this: