title: Making use of all available RAM in a Haskell program?
body: <p>I have 8 GB of RAM, but Haskell programs seemingly can only use 1.3 GB.</p>
  
  <p>I'm using this simple program to determine how much memory a GHC program can allocate:</p>
  
  <pre><code>import System.Environment
  import Data.Set as Set
  
  main = do
           args &lt;- getArgs
           let n = (read $ args !! 0) :: Int
               s = Set.fromList [0..n]
           do
             putStrLn $ "min: " ++ (show $ findMin s)
             putStrLn $ "max: " ++ (show $ findMax s)
  </code></pre>
  
  <p>Here's what I'm finding:</p>
  
  <ul>
  <li>running <code>./mem.exe 40000000 +RTS -s</code> succeeds and reports <code>1113 MB total memory in use</code></li>
  <li>running <code>./mem.exe 42000000 +RTS -s</code> fails with <code>out of memory error</code></li>
  <li>running <code>./mem.exe 42000000 +RTS -s -M4G</code> errors out with <code>-M4G: size outside allowed range</code></li>
  <li>running <code>./mem.exe 42000000 +RTS -s -M3.9G</code> fails with <code>out of memory error</code></li>
  </ul>
  
  <p>Monitoring the process via the Windows Task Manager shows that the max memory usage is about 1.2 GB.</p>
  
  <p>My system: Win7, 8 GB RAM, Haskell Platform 2011.04.0.0, ghc 7.0.4.</p>
  
  <p>I'm compiling with: <code>ghc -O2 mem.hs -rtsopts</code></p>
  
  <p>How can I make use of all of my available RAM? Am I missing something obvious?</p>