title: Memory Allocation "Error: cannot allocate vector of size 75.1 Mb"
body: <p>In the course of vectorizing some simulation code, I've run into a memory issue. I'm using 32 bit R version 2.15.0 (via RStudio version 0.96.122) under Windows XP. My machine has 3.46 GB of RAM.</p>
  
  <pre><code>&gt; sessionInfo()
  R version 2.15.0 (2012-03-30)
  Platform: i386-pc-mingw32/i386 (32-bit)
  
  locale:
  [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
  [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
  [5] LC_TIME=English_United Kingdom.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] Matrix_1.0-6   lattice_0.20-6 MASS_7.3-18   
  
  loaded via a namespace (and not attached):
  [1] grid_2.15.0  tools_2.15.0
  </code></pre>
  
  <p>Here is a minimal example of the problem:</p>
  
  <pre><code>&gt; memory.limit(3000)
  [1] 3000
  &gt; rm(list = ls())
  &gt; gc()
            used (Mb) gc trigger  (Mb)  max used   (Mb)
  Ncells 1069761 28.6    1710298  45.7   1710298   45.7
  Vcells  901466  6.9   21692001 165.5 173386187 1322.9
  &gt; N &lt;- 894993
  &gt; library(MASS)
  &gt; sims &lt;- mvrnorm(n = N, mu = rep(0, 11), Sigma = diag(nrow = 11))
  &gt; sims &lt;- mvrnorm(n = N + 1, mu = rep(0, 11), Sigma = diag(nrow = 11))
  Error: cannot allocate vector of size 75.1 Mb
  </code></pre>
  
  <p>(In my application the covariance matrix Sigma is not diagonal, but I get the same error either way.) </p>
  
  <p>I've spent the afternoon reading about memory allocation issues in R (including <a href="https://stackoverflow.com/questions/5171593/r-memory-management-cannot-allocate-vector-of-size-n-mb">here</a>, <a href="https://stackoverflow.com/questions/6198531/r-ggplot2-cannot-allocate-vector-of-size-128-0-mb">here</a> and <a href="https://stackoverflow.com/questions/8920722/cannot-allocate-vector-in-r-despite-being-in-64-bit-version">here</a>). From what I've read, I get the impression that it's not a matter of the available RAM per se, but of the available continuous address space. Still, 75.1Mb seems pretty small to me.</p>
  
  <p>I'd greatly appreciate any thoughts or suggestions that you might have. </p>