{"id":96955,"date":"2017-09-06T07:00:00","date_gmt":"2017-09-06T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=96955"},"modified":"2019-03-13T01:16:31","modified_gmt":"2019-03-13T08:16:31","slug":"20170906-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20170906-00\/?p=96955","title":{"rendered":"Can I enable Large Address Awareness dynamically at runtime?"},"content":{"rendered":"<p><a HREF=\"https:\/\/docs.microsoft.com\/cpp\/build\/reference\/largeaddressaware-handle-large-addresses\">The <code>\/LARGE&shy;ADDRESS&shy;AWARE<\/code> flag<\/a> is recorded <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20150518-00\/?p=45581\">in the header of the executable<\/a>. A customer wanted to know if there was a way to select at runtime whether a process is large address aware. They were willing to accept an override in <code>Image File Execution Options<\/code>, if that&#8217;s what it took. The customer wanted to do this as part of a <a HREF=\"https:\/\/msdn.microsoft.com\/library\/mt238502.aspx\">feature-flight<\/a>, but they were concerned that third-party add-ins may behave unexpectedly when run in a large-address-aware process, and they would like a way to disable large address awareness on the fly. <\/p>\n<p>Unfortunately, there is no way to change the setting at runtime, nor is there an override in <code>Image File Execution Options<\/code>. The value in the header of the executable is what the system uses to determine whether to give the process access to address space above the 2<a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20090611-00\/?p=17933\">GB<\/a> boundary. <\/p>\n<p>But wait, all is not lost. <\/p>\n<p>What the customer could do is ship <i>two<\/i> versions of the program, byte-for-byte identical except that one of them has the <code>\/LARGE<\/code><code>ADDRESS<\/code><code>AWARE<\/code> flag set, and the other has it clear.&sup1; They could then have their feature-flight system update the Start menu shortcut to point to the one that they want to test. <\/p>\n<p>Another approach is to register the large-address-aware version in the Start menu, and have it check the feature-flight flag when it is launched. If the flag says to disable large-address-awareness, then the program launches the not-large-address-aware version with the same command line. <\/p>\n<p>Yes, it&#8217;s a bit clunky, but at least it&#8217;s do-able. <\/p>\n<p>&sup1; To reduce disk space, they could move the bulk of their code into a DLL and have the EXE be a stub that loads the DLL and then calls the <code>Run&shy;The&shy;Program<\/code> function in the dll. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>No, but you can maybe fake it.<\/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-96955","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>No, but you can maybe fake it.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/96955","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=96955"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/96955\/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=96955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=96955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=96955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}