\HeaderA{Rprofmem}{Enable Profiling of R's Memory Use}{Rprofmem}
\keyword{utilities}{Rprofmem}
\begin{Description}\relax
Enable or disable reporting of memory allocation in R.
\end{Description}
\begin{Usage}
\begin{verbatim}
Rprofmem(filename = "Rprofmem.out", append = FALSE, threshold = 0)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{filename}] The file to be used for recording the memory
allocations. Set to \code{NULL} or \code{""} to disable reporting. 
\item[\code{append}] logical: should the file be over-written or appended to? 
\item[\code{threshold}] numeric: allocations on R's "large vector" heap
larger than this number of bytes will be reported.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Enabling profiling automatically disables any existing profiling to
another or the same file.

Profiling writes the call stack to the specified file every time
\code{malloc} is called to allocate a large vector object or to
allocate a page of memory for small objects. The size of a page of
memory and the size above which \code{malloc} is used for vectors are
compile-time constants, by default 2000 and 128 bytes respectively.

The profiler tracks allocations, some of which will be to previously
used memory and will not increase the total memory use of R.
\end{Details}
\begin{Value}
None
\end{Value}
\begin{Note}\relax
The memory profiler slows down R even when not in use, and so is a
compile-time option.  The memory profiler can be used at the same time
as other R and C profilers.
\end{Note}
\begin{SeeAlso}\relax
The R sampling profiler, \code{\LinkA{Rprof}{Rprof}} also collects
memory information.

\code{\LinkA{tracemem}{tracemem}} traces duplications of specific objects.

The "Writing R Extensions" manual section on "Tidying and profiling R code"
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}## Not run: 
## not supported unless R is compiled to support it.
Rprofmem("Rprofmem.out", threshold=1000)
example(glm)
Rprofmem(NULL)
noquote(readLines("Rprofmem.out", n=5))
## End(Not run)\end{ExampleCode}
\end{Examples}

