Skip to content
Prev 45565 / 63421 Next

R 3.0.0 memory use

On 04/14/2013 07:11 PM, luke-tierney at uiowa.edu wrote:
I can't quite tell from Tim's script what he's documenting. In R-2.15.3 I have

 > Rprofmem(); Rprofmem(NULL); readLines("Rprofmem.out", warn=FALSE)
character(0)

(or sometimes [1] "new page:new page:\"Rprofmem\" ")

whereas in R-3.0.0

 > Rprofmem(); Rprofmem(NULL); readLines("Rprofmem.out", warn=FALSE)
[1] "320040 :80040 :240048 :320040 :80040 :240048 :"

I think these are the allocations Tim is seeing. They're from the parser (see 
below) rather than as.data.frame. For Tim's example

   y <- 1:10^4 + 0.0
   Rprofmem(); d <- as.data.frame(y); Rprofmem(NULL); readLines("Rprofmem.out")

[1] "320040 :80040 :240048 :320040 :80040 :240048 :80040 
:\"as.data.frame.numeric\" \"as.data.frame\" "
[2] "320040 :80040 :240048 :320040 :80040 :240048 :"

only the allocation 80040 is from as.data.frame (from the call stack output).

Under R -d gdb

   (gdb) b R_OutputStackTrace
   (gdb) r
   > Rprofmem(); Rprofmem(NULL)

   Breakpoint 1, R_OutputStackTrace (file=0xbd43f0) at 
/home/mtmorgan/src/R-3-0-branch/src/main/memory.c:3434
   3434	{
   (gdb) bt
   #0  R_OutputStackTrace (file=0xbd43f0) at 
/home/mtmorgan/src/R-3-0-branch/src/main/memory.c:3434
   #1  0x00007ffff792ff83 in R_ReportAllocation (size=320040) at 
/home/mtmorgan/src/R-3-0-branch/src/main/memory.c:3456
   #2  Rf_allocVector (type=13, length=80000) at 
/home/mtmorgan/src/R-3-0-branch/src/main/memory.c:2478
   #3  0x00007ffff790bedf in growData () at gram.y:3391

and the memory allocations are from these lines in the parser gram.y

	PROTECT( bigger = allocVector( INTSXP, data_size * DATA_ROWS ) ) ;
	PROTECT( biggertext = allocVector( STRSXP, data_size ) );

I'm not sure why these show up under R 3.0.0, though.

$ R-2-15-branch/bin/R --version
R version 2.15.3 Patched (2013-03-13 r62579) -- "Security Blanket"
Copyright (C) 2013 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)

R-3-0-branch$ bin/R --version
R version 3.0.0 Patched (2013-04-14 r62579) -- "Masked Marvel"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

Martin