by Michael S. Kaplan, published on 2007/05/25 10:05 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2007/05/25/2871960.aspx
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))
cbxFontName.Items.Add(font);
}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.
Thanks,
Georg
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)