Rev 27447 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{Memory}\alias{Memory}\alias{mem.limits}\title{Memory Available for Data Storage}\description{Use command line options to control the memory available for \R.}\usage{#ifdef unixR --min-vsize=vl --max-vsize=vu --min-nsize=nl --max-nsize=nu#endif#ifdef windowsRgui --min-vsize=vl --max-vsize=vu --min-nsize=nl --max-nsize=nuRterm --min-vsize=vl --max-vsize=vu --min-nsize=nl --max-nsize=nu#endifmem.limits(nsize = NA, vsize = NA)}\arguments{\item{vl, vu, vsize}{Heap memory in bytes.}\item{nl, nu, nsize}{Number of cons cells.}}\details{\R has a variable-sized workspace (from version 1.2.0). There is nowmuch less need to set memory options than previously, and mostusers will never need to set these. They are provided both as a wayto control the overall memory usage (which can also be done#ifdef unixby operating-system facilities such as \code{limit} on Unix),#endif#ifdef windowsusing the option \option{--max-mem-size} on Windows),#endifand since setting larger values of the minima will make \R slightlymore efficient on large tasks.#ifdef windows(On Windows the \option{--max-mem-size} option sets the maximum memoryallocation: it has a minimum allowed value of 10M. This is intendedto catch attempts to allocate excessive amounts of memory which maycause other processes to run out of resources. The default is thesmaller of the amount of physical RAM in the machine and 256Mb.See also \code{\link[utils]{memory.limit}}.)#endifTo understand the options, one needs to know that \R maintainsseparate areas for fixed and variable sized objects. The first of theseis allocated as an array of \dQuote{\emph{cons cells}} (Lisp programmers willknow what they are, others may think of them as the building blocks ofthe language itself, parse trees, etc.), and the second are thrown on a\dQuote{\emph{heap}} of \dQuote{Vcells} of 8 bytes each. Effectively,the input \code{v} is rounded up to the nearest multiple of 8.Each cons cell occupies 28 bytes on a 32-bit machine, (usually) 56 byteson a 64-bit machine.The \option{--*-nsize} options can be used to specify the number ofcons cells and the \option{--*-vsize} options specify the size of thevector heap in bytes. Both options must be integers or integersfollowed by \code{G}, \code{M}, \code{K}, or \code{k} meaning\code{Giga} (\eqn{2^{30} = 1073741824}) \emph{Mega} (\eqn{2^{20} =1048576}), (computer) \emph{Kilo} (\eqn{2^{10} = 1024}), or regular\emph{kilo} (1000).The \option{--min-*} options set the minimal sizes for the number ofcons cells and for the vector heap. These values are also the initialvalues, but thereafter \R will grow or shrink the areas depending onusage, but never exceeding the limits set by the \option{--max-*}options nor decreasing below the initial values.The default values are currently minima of 350k cons cells,6Mb of vector heapand no maxima (other than machine resources). The maxima can bechanged during an \R session by calling \code{mem.limits}. (If this iscalled with the default values, it reports the current settings.)You can find out the current memory consumption (the heap and conscells used as numbers and megabytes) by typing \code{\link{gc}()} at the\R prompt. Note that following \code{\link{gcinfo}(TRUE)}, automaticgarbage collection always prints memory use statistics. Maxima willnever be reduced below the current values for triggering garbagecollection, and attempts to do so will be silently ignored.% The defaults for \option{--min-nsize} and \option{--min-vsize} can be% changed by setting the environment variables \env{R\_NSIZE} and% \env{R\_VSIZE} respectively, perhaps most conveniently in the file% \file{.Renviron} or \file{\eqn{\sim}{~}/.Renviron}. There should no% longer be any need to do so.When using \code{\link{read.table}}, the memory requirements are infact higher than anticipated, because the file is first read in as onelong string which is then split again. Use \code{\link{scan}} ifpossible in case you run out of memory when reading in a large table.}\value{(\code{mem.limits}) an integer vector giving the current settings ofthe maxima, possibly \code{NA}.}\seealso{\code{\link{gc}} for information on the garbage collector,\code{\link{memory.profile}} for profiling the usage of cons cells.#ifdef windows\code{\link[utils]{memory.size}} to monitor total memory usage,\code{\link[utils]{memory.limit}} for the current limit.#endif}\note{For backwards compatibility, options \option{--nsize} and\option{--vsize} are equivalent to \option{--min-nsize} and\option{--min-vsize}.#ifdef windowsWhen using the \code{Rgui} console it is simplest to make a shortcut andput these command-line flags at the end of the Target field.#endif}\examples{# Start R with 10MB of heap memory and 500k cons cells, limit to# 100Mb and 1M cells\dontrun{## UnixR --min-vsize=10M --max-vsize=100M --min-nsize=500k --max-nsize=1M}}\keyword{environment}