UppercuT – Mark an Application Executable to Use More Than 2GB of Memory (Large Address Aware)

If you’ve ever built a .NET application that runs out of memory constantly, it’s because you are hitting a 2GB limit. You may have known about marking an assembly “/largeaddressaware”. You may have not. The process of doing this is actually somewhat easy once you learn about it. You normally just start a Visual Studio Command Prompt (found in Start Menu under Microsoft Visual Studio version/Visual Studio Tools). Then you find the compiled application and run the following command:

editbin /largeaddressaware yourassembly.exe

That’s really all you need to do get more memory out of your application. There are some great resources on how and why in the two blog posts below.

I would instead like to concentrate on automation with UppercuT

Getting UppercuT to Automatically Mark an Assembly for More Than 2GB of Memory

We are going to make a custom AFTER task for the compile step of UppercuT. With that we are going to specify the executable to mark. When the application is built (on the build server), it is marked for address large amounts of freakin memory. *grin*

1. If you do not have a BuildScripts.Custom folder, create one.

 image

2. In that folder we need to create a file named “_compile.post.build.”

  image

3. Open the file in a text editor and insert the code below.

Contents of _compile.post.build (this simulates the VS2005 command prompt and calls editbin for you)

<?xml version="1.0" encoding="utf-8" ?>
<project name="Compiler" default="go">
  <property name="build.config.settings" value="__NONE__" overwrite="false" />
  <include buildfile="${build.config.settings}" if="${file::exists(build.config.settings)}" />
  <property name="dirs.current" value="${directory::get-parent-directory(project::get-buildfile-path())}" />
  <property name="dirs.build" value="${dirs.current}\..\build_output" />
  <property name="exe.name" value="__INSERT_NAME_HERE__" overwrite="false" />
  <property name="program.largeaware" value="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\VC\bin\editbin.exe" />
  <property name="args.largeaware" value="/LARGEADDRESSAWARE ${dirs.build}\${exe.name}" />
  <property name="environment.properties.largeaware" value="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\VC\vcvarsall.bat x86" />

  <target name="go" depends="set_large_aware" description="Compiling project." />

  <target name="set_large_aware" depends="" description="Building Library">
    <echo message="Setting the application ${dirs.build}\${app.name} to large aware."/>
    <exec program="${program.largeaware}">
      <environment>
        <variable name="VSINSTALLDIR" value="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8" />
        <variable name="VCINSTALLDIR" value="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\VC" />
        <variable name="FrameworkDir" value="${environment::get-folder-path('System')}\..\Microsoft.NET\Framework" />
        <variable name="FrameworkVersion" value="v2.0.50727" />
        <variable name="FrameworkSDKDir" value="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\SDK\v2.0" />
        <variable name="DevEnvDir" value="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\Common7\IDE" />
        <variable name="PATH" path="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\Common7\IDE;${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\VC\BIN;${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\Common7\Tools;${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\SDK\v2.0\bin;${environment::get-folder-path('System')}\..\Microsoft.NET\Framework\v2.0.50727;${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\VC\VCPackages;%PATH%" />
        <variable name="INCLUDE" path="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\VC\INCLUDE;${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\SDK\v2.0\include;%INCLUDE%" />
        <variable name="LIB" path="${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\VC\LIB;${environment::get-folder-path('ProgramFiles')}\Microsoft Visual Studio 8\SDK\v2.0\lib;%LIB%" />
        <variable name="LIBPATH" path="${environment::get-folder-path('System')}\..\Microsoft.NET\Framework\v2.0.50727" />
      </environment>
      <arg line="${args.largeaware}" />
    </exec>
  </target>

<!--
All of the variables from where they are actually set - C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat
-->

</project>

4. Change the property exe.name value to insert the name of the executable. UppercuT already knows where the file is going to get built.

 image

5. Add that file to source control.

6. Run a local build to be sure everything is good and then check that puppy in!

7. Crack open a beer *ahem* soda and sip in the sweet taste of success.

That’s it! Once that stuff is in source control, your automated build will take care of the rest! You can now officially be lazy about this setting from now on.

Check out some of the other UppercuT posts! UppercuT category

With this knowledge you shall build.

 

kick it on DotNetKicks.com

Print | posted @ Thursday, August 20, 2009 1:42 AM

Comments on this entry:

Gravatar # re: UppercuT – Mark an Application Executable to Use More Than 2GB of Memory (Large Address Aware)
by dru Sellers at 8/20/2009 4:55 AM

you might put the piece I have to change at the very top, rather than burying it in all the other properties.
Gravatar # re: UppercuT – Mark an Application Executable to Use More Than 2GB of Memory (Large Address Aware)
by Robz at 8/20/2009 8:40 AM

I thought about it, but I wanted to see if you would comment if I didn't. ;)
Comments have been closed on this topic.