{"id":3963,"date":"2013-06-28T07:00:00","date_gmt":"2013-06-28T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/06\/28\/its-the-address-space-stupid\/"},"modified":"2013-06-28T07:00:00","modified_gmt":"2013-06-28T07:00:00","slug":"its-the-address-space-stupid","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130628-00\/?p=3963","title":{"rendered":"It&#8217;s the address space, stupid"},"content":{"rendered":"<p>Nowadays, computers have so much memory that running out of RAM is rarely the cause for an &#8220;out of memory&#8221; error.<\/p>\n<p> Actually, let&#8217;s try that again. For over a decade, <a href=\"http:\/\/ns1758.ca\/winch\/winchest.html\"> hard drive have been so large<\/a> (and <a href=\"http:\/\/www.mkomo.com\/cost-per-gigabyte\">cheap<\/a>) that running out of swap space is rarely the cause for an &#8220;out of memory&#8221; error. <\/p>\n<p> In user-mode, the term <i>memory<\/i> <a href=\"http:\/\/blogs.msdn.com\/b\/ericlippert\/archive\/2009\/06\/08\/out-of-memory-does-not-refer-to-physical-memory.aspx\"> refers to virtual memory, not physical RAM chips<\/a>. The amount of physical RAM doesn&#8217;t affect how much memory a user-mode application can allocate; it&#8217;s all about commit and swap space.&sup1; But swap space is disk space, and that is in the hundreds of gigabytes for hard drives. (Significantly less for SSDs, but even in that case, it&#8217;s far more than 4<a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2009\/06\/11\/9725386.aspx\">GB<\/a>.) <\/p>\n<p> The limiting factor these days is address space. <\/p>\n<p> Each thread&#8217;s stack takes a megabyte, and if you&#8217;re creating a lot of threads, that can add up to a lot of address space consumed just for stacks. And then you have to include the address space for the DLLs you&#8217;ve loaded (which quickly adds up). And then there&#8217;s the address space for all the memory you allocated. (Even if you don&#8217;t end up using it, it still occupies address space until you free it.) <\/p>\n<p> Typically, when you get an <code>ERROR_OUT_OF_MEMORY<\/code> error, the problem isn&#8217;t physical memory or virtual memory. It&#8217;s address space. <\/p>\n<p> This is one of the main benefits of moving to 64-bit computing. It&#8217;s not that you actually are going to use or need all that memory. But it relieves pressure on the address space: The user-mode address space in 64-bit Windows is eight <i>terabytes<\/i>. <\/p>\n<p> When the day comes that eight terabytes is not enough, we at least won&#8217;t have to redesign the application model to expand the address space. The current x86-64 hardware has support for address spaces of up to 256TB, and the theoretical address space for a 64-bit processor is sixteen exabytes. <\/p>\n<p> &sup1; Of course, physical RAM is a factor if the application is explicitly allocating physical memory, but that&#8217;s the exception rather than the rule. <\/p>\n<p> <b>Exercise<\/b>: Help this customer clear up their confusion: They reported that processes were failing to start with <code>STATUS_DLL_INIT_FAILED<\/code> (0xC0000142), and our diagnosis was that the <a href=\"http:\/\/blogs.msdn.com\/b\/ntdebugging\/archive\/2007\/01\/04\/desktop-heap-overview.aspx\"> desktop heap<\/a> was exhausted. &#8220;The system has 8GB of RAM installed, and Task Manager reports that only 2GB of it is being used, so it is unlikely that I am running out of any kind of heap\/memory.&#8221; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nowadays, computers have so much memory that running out of RAM is rarely the cause for an &#8220;out of memory&#8221; error. Actually, let&#8217;s try that again. For over a decade, hard drive have been so large (and cheap) that running out of swap space is rarely the cause for an &#8220;out of memory&#8221; error. In [&hellip;]<\/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":[25],"class_list":["post-3963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Nowadays, computers have so much memory that running out of RAM is rarely the cause for an &#8220;out of memory&#8221; error. Actually, let&#8217;s try that again. For over a decade, hard drive have been so large (and cheap) that running out of swap space is rarely the cause for an &#8220;out of memory&#8221; error. In [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3963","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=3963"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3963\/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=3963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}