{"id":43783,"date":"2014-10-23T07:00:00","date_gmt":"2014-10-23T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/10\/23\/how-can-i-detect-programmatically-whether-the-3gb-switch-is-enabled\/"},"modified":"2014-10-23T07:00:00","modified_gmt":"2014-10-23T07:00:00","slug":"how-can-i-detect-programmatically-whether-the-3gb-switch-is-enabled","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20141023-00\/?p=43783","title":{"rendered":"How can I detect programmatically whether the \/3GB switch is enabled?"},"content":{"rendered":"<p>\nA customer was doing some diagnostic work and wanted a way to detect\nwhether the\n<code>\/3GB<\/code> switch was enabled.\n(Remember that the <code>\/3GB<\/code> switch is\nmeaningful only for 32-bit versions of Windows.)\n<\/p>\n<p>\nThe way to detect the setting is to call\n<code>Get&shy;System&shy;Info<\/code> and look at the\n<code>lp&shy;Maximum&shy;Application&shy;Address<\/code>.\n<\/p>\n<pre>\n#include &lt;windows.h&gt;\n#include &lt;stdio.h&gt;\nint __cdecl main(int, char **)\n{\n SYSTEM_INFO si;\n GetSystemInfo(&amp;si);\n printf(\"%p\", si.lpMaximumApplicationAddress);\n return 0;\n}\n<\/pre>\n<p>\nCompile this <i>as a 32-bit program<\/i>\nand run it.\n<\/p>\n<table BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>Configuration<\/th>\n<th>LARGE&shy;ADDRESS&shy;AWARE?<\/th>\n<th>Result<\/th>\n<th>Meaning<\/th>\n<\/tr>\n<tr>\n<td>32-bit Windows, standard configuration<\/td>\n<td>Any<\/td>\n<td>7FFEFFFF<\/td>\n<td>2<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2009\/06\/11\/9725386.aspx\">GB<\/a>\n    <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/10\/08\/55239.aspx\">\n    minus 64KB<\/a><\/td>\n<\/tr>\n<tr>\n<td>32-bit Windows, \/3GB<\/td>\n<td>Any<\/td>\n<td>BFFFFFFF<\/td>\n<td>3GB<\/td>\n<\/tr>\n<tr>\n<td>32-bit Windows,\n    <a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/hardware\/ff542202(v=vs.85).aspx\">increaseuserva<\/a> = 2995<\/td>\n<td>Any<\/td>\n<td>BB3EFFFF<\/td>\n<td>2995 MB<\/td>\n<\/tr>\n<tr>\n<td>64-bit Windows<\/td>\n<td>No<\/td>\n<td>7FFEFFFF<\/td>\n<td>2GB minus 64KB<\/td>\n<\/tr>\n<tr>\n<td>64-bit Windows<\/td>\n<td><a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2005\/06\/01\/423817.aspx\">\n    Yes<\/a><\/td>\n<td>FFFEFFFF<\/td>\n<td>4GB <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2009\/06\/11\/9725386.aspx\">minus 64KB<\/a><\/td>\n<\/tr>\n<\/table>\n<p>\nOn 32-bit systems, this reports the system-wide setting that\nspecifies the maximum user-mode address space,\nregardless of how your application is marked.\nNote, however, that your application must be marked\n<code>LARGE&shy;ADDRESS&shy;AWARE<\/code>\nin order to take advantage of the space above 2GB.\n<\/p>\n<p>\nOn the other hand,\nwhen you run a 32-bit application on 64-bit Windows,\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2008\/12\/22\/9244582.aspx\">\nit runs the application in an emulation layer<\/a>.\nTherefore, 64-bit Windows can give each application a different view of\nthe system.\nIn particular, depending on how your application is marked,\nWindows can emulate a 32-bit system with or without the\n<code>\/3GB<\/code> switch enabled,\nbased on what the application prefers.\n<\/p>\n<p>\nArmed with this knowledge, perhaps you can help this customer.\nRemember, you sometimes need to\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/06\/20\/10427187.aspx\">\ngo beyond simply answering the question\nand actually solve the customer&#8217;s problem<\/a>.\n<\/p>\n<blockquote CLASS=\"m\">\n<p>\nWe would like to know how to detect from our 32-bit application\nwhether the host operating system is 64-bit or 32-bit.\n<\/p>\n<p>\nWe need to know this because our program does some data processing,\nand we have to choose an appropriate algorithm.\nWe have written one algorithm that is faster but uses\n1&frac12;<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2009\/06\/11\/9725386.aspx\">GB<\/a>\nof address space,\nand we have also written\na fallback algorithm that is slower but does not\nuse anywhere near as much address space.\nWhen running on a native 32-bit system,\nthere is typically not 1&frac12;GB of address space available,\nso we have to use the slow algorithm.\nBut when running on a native 64-bit system\n(or a native 32-bit system with the <code>\/3GB<\/code> switch enabled),\nour program can use the fast algorithm.\nTherefore, we would like to detect\nwhether the native operating system\nis 64-bit so that we can decide whether to use the fast or slow algorithm.\n<\/p>\n<\/blockquote>\n<p>\nHere&#8217;s another customer question you can now answer:\n<\/p>\n<blockquote CLASS=\"m\">\n<p>\nWe have a 64-bit program, and since we know that Windows currently\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa366778(v=vs.85).aspx#memory_limits\">\ndoes not use the full 64-bit address space<\/a>,\nwe would like to\nsteal the upper bits of the pointer to hold additional information:\nIf there are at least 8 bits available, we can use a more efficient\ndata format.\nOtherwise, we fall back to a less efficient format.\nHow can we detect whether the upper 8 bits are being used for\naddressing?\n<\/p>\n<\/blockquote>\n<p>\n<b>Update<\/b>: Clarified the table based on misunderstanding\nin comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer was doing some diagnostic work and wanted a way to detect whether the \/3GB switch was enabled. (Remember that the \/3GB switch is meaningful only for 32-bit versions of Windows.) The way to detect the setting is to call Get&shy;System&shy;Info and look at the lp&shy;Maximum&shy;Application&shy;Address. #include &lt;windows.h&gt; #include &lt;stdio.h&gt; int __cdecl main(int, char [&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-43783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer was doing some diagnostic work and wanted a way to detect whether the \/3GB switch was enabled. (Remember that the \/3GB switch is meaningful only for 32-bit versions of Windows.) The way to detect the setting is to call Get&shy;System&shy;Info and look at the lp&shy;Maximum&shy;Application&shy;Address. #include &lt;windows.h&gt; #include &lt;stdio.h&gt; int __cdecl main(int, char [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43783","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=43783"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43783\/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=43783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}