{"id":43203,"date":"2015-01-07T07:00:00","date_gmt":"2015-01-07T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2015\/01\/07\/why-is-there-a-bstr-cache-anyway\/"},"modified":"2019-03-13T12:11:51","modified_gmt":"2019-03-13T19:11:51","slug":"20150107-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150107-00\/?p=43203","title":{"rendered":"Why is there a BSTR cache anyway?"},"content":{"rendered":"<p>The <code>Sys&shy;Alloc&shy;String<\/code> function uses a cache of <code>BSTR<\/code>s <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2009\/11\/27\/9929238.aspx\">which can mess up your performance tracing<\/a>. <a HREF=\"http:\/\/blogs.msdn.com\/b\/larryosterman\/archive\/2004\/09\/28\/235304.aspx\">There is a switch for disabling it for debugging purposes<\/a>, but <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2012\/01\/23\/10259472.aspx#10259779\">why does the cache exist at all<\/a>? <\/p>\n<p>The <code>BSTR<\/code> cache is a historical artifact. When <code>BSTR<\/code>s were originally introduced, performance tracing showed that a significant chunk of time was spent merely allocating and freeing memory in the heap manager. Using a cache reduced the heap allocation overhead significantly. <\/p>\n<p>In the intervening years, um, decades, the performance of the heap manager has improved to the point where the cache isn&#8217;t necessary any more. But the <code>Sys&shy;Alloc&shy;String<\/code> people can&#8217;t get rid of the <code>BSTR<\/code> because <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2012\/01\/23\/10259472.aspx\">so many applications unwittingly rely on it<\/a>. <\/p>\n<p>The <code>BSTR<\/code> cache is now a compatibility constraint. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It was useful, once.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-43203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>It was useful, once.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=43203"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=43203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}