More significant than petty cache

by Michael S. Kaplan, published on 2007/05/25 10:05 -04:00, original URI:

Georg asked:

One of my customers is enumerating fonts using the following code construct:

foreach (FontFamily font in FontFamily.Families) {
        if (font.IsStyleAvailable(FontStyle.Regular))

They are wondering regarding the performance of this enumeration. First run of the test app takes about 2 seconds, all consecutive runs take about 0.2 secons. I assume this has to do with some memory caching.


Well, in a way it is caching, but no so much memory caching. In this case it is the one time hit (per session) of creating every single font.

You can see a somewhat analogous hit if you use CultureInfo.GetCultures, and that bit of caching will only last for as long as the process is around since CultureInfo objects are not put in any kind of session level caching like fonts are....

Although in this case memory caching may make it a little bit faster from time to time. :-)

I should probably talk about the Window side of all this, but I will let that wait for an upcoming post....


This post brought to you by(U+1038, a.k.a. MYANMAR SIGN VISARGA)

no comments

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day