| 3076 |
pd |
1 |
\name{Memory}
|
| 7211 |
hornik |
2 |
\alias{Memory}
|
| 11197 |
ripley |
3 |
\alias{mem.limits}
|
| 3076 |
pd |
4 |
\title{Memory Available for Data Storage}
|
| 7232 |
hornik |
5 |
\description{
|
| 11197 |
ripley |
6 |
Use command line options to control the memory available for \R.
|
| 7232 |
hornik |
7 |
}
|
| 3076 |
pd |
8 |
\usage{
|
| 7422 |
ripley |
9 |
#ifdef unix
|
| 11231 |
ripley |
10 |
R --min-vsize=vl --max-vsize=vu --min-nsize=nl --max-nsize=nu
|
| 7422 |
ripley |
11 |
#endif
|
|
|
12 |
#ifdef windows
|
| 11231 |
ripley |
13 |
Rgui --min-vsize=vl --max-vsize=vu --min-nsize=nl --max-nsize=nu
|
|
|
14 |
Rterm --min-vsize=vl --max-vsize=vu --min-nsize=nl --max-nsize=nu
|
| 7422 |
ripley |
15 |
#endif
|
| 11197 |
ripley |
16 |
|
|
|
17 |
mem.limits(nsize = NA, vsize = NA)
|
| 3076 |
pd |
18 |
}
|
|
|
19 |
\arguments{
|
| 11231 |
ripley |
20 |
\item{vl, vu, vsize}{Heap memory in bytes.}
|
|
|
21 |
\item{nl, nu, nsize}{Number of cons cells.}
|
| 3076 |
pd |
22 |
}
|
|
|
23 |
\details{
|
| 11197 |
ripley |
24 |
\R has a variable-sized workspace (from version 1.2.0). There is now
|
|
|
25 |
much less need to set memory options than previously, and most
|
|
|
26 |
users will never need to set these. They are provided both as a way
|
|
|
27 |
to control the overall memory usage (which can also be done
|
|
|
28 |
#ifdef unix
|
|
|
29 |
by operating-system facilities such as \code{limit} on Unix),
|
|
|
30 |
#endif
|
|
|
31 |
#ifdef windows
|
| 25260 |
hornik |
32 |
using the option \option{--max-mem-size} on Windows),
|
| 11197 |
ripley |
33 |
#endif
|
| 25260 |
hornik |
34 |
and since setting larger values of the minima will make \R slightly
|
|
|
35 |
more efficient on large tasks.
|
| 10172 |
luke |
36 |
|
| 12256 |
pd |
37 |
#ifdef windows
|
| 25260 |
hornik |
38 |
(On Windows the \option{--max-mem-size} option sets the maximum memory
|
| 12256 |
pd |
39 |
allocation: it has a minimum allowed value of 10M. This is intended
|
|
|
40 |
to catch attempts to allocate excessive amounts of memory which may
|
|
|
41 |
cause other processes to run out of resources. The default is the
|
|
|
42 |
smaller of the amount of physical RAM in the machine and 256Mb.
|
| 27447 |
ripley |
43 |
See also \code{\link[utils]{memory.limit}}.)
|
| 12256 |
pd |
44 |
#endif
|
|
|
45 |
|
| 11197 |
ripley |
46 |
To understand the options, one needs to know that \R maintains
|
|
|
47 |
separate areas for fixed and variable sized objects. The first of these
|
| 25118 |
hornik |
48 |
is allocated as an array of \dQuote{\emph{cons cells}} (Lisp programmers will
|
| 11197 |
ripley |
49 |
know what they are, others may think of them as the building blocks of
|
|
|
50 |
the language itself, parse trees, etc.), and the second are thrown on a
|
| 25118 |
hornik |
51 |
\dQuote{\emph{heap}} of \dQuote{Vcells} of 8 bytes each. Effectively,
|
|
|
52 |
the input \code{v} is rounded up to the nearest multiple of 8.
|
| 10172 |
luke |
53 |
|
| 11277 |
ripley |
54 |
Each cons cell occupies 28 bytes on a 32-bit machine, (usually) 56 bytes
|
| 11197 |
ripley |
55 |
on a 64-bit machine.
|
| 3076 |
pd |
56 |
|
| 25260 |
hornik |
57 |
The \option{--*-nsize} options can be used to specify the number of
|
|
|
58 |
cons cells and the \option{--*-vsize} options specify the size of the
|
|
|
59 |
vector heap in bytes. Both options must be integers or integers
|
|
|
60 |
followed by \code{G}, \code{M}, \code{K}, or \code{k} meaning
|
|
|
61 |
\code{Giga} (\eqn{2^{30} = 1073741824}) \emph{Mega} (\eqn{2^{20} =
|
|
|
62 |
1048576}), (computer) \emph{Kilo} (\eqn{2^{10} = 1024}), or regular
|
|
|
63 |
\emph{kilo} (1000).
|
| 3609 |
pd |
64 |
|
| 25260 |
hornik |
65 |
The \option{--min-*} options set the minimal sizes for the number of
|
| 11197 |
ripley |
66 |
cons cells and for the vector heap. These values are also the initial
|
|
|
67 |
values, but thereafter \R will grow or shrink the areas depending on
|
| 25260 |
hornik |
68 |
usage, but never exceeding the limits set by the \option{--max-*}
|
| 11197 |
ripley |
69 |
options nor decreasing below the initial values.
|
| 7346 |
ripley |
70 |
|
| 11197 |
ripley |
71 |
The default values are currently minima of 350k cons cells,
|
|
|
72 |
6Mb of vector heap
|
|
|
73 |
and no maxima (other than machine resources). The maxima can be
|
|
|
74 |
changed during an \R session by calling \code{mem.limits}. (If this is
|
|
|
75 |
called with the default values, it reports the current settings.)
|
|
|
76 |
|
| 5055 |
pd |
77 |
|
| 11197 |
ripley |
78 |
You can find out the current memory consumption (the heap and cons
|
|
|
79 |
cells used as numbers and megabytes) by typing \code{\link{gc}()} at the
|
|
|
80 |
\R prompt. Note that following \code{\link{gcinfo}(TRUE)}, automatic
|
|
|
81 |
garbage collection always prints memory use statistics. Maxima will
|
|
|
82 |
never be reduced below the current values for triggering garbage
|
|
|
83 |
collection, and attempts to do so will be silently ignored.
|
| 3076 |
pd |
84 |
|
| 25260 |
hornik |
85 |
% The defaults for \option{--min-nsize} and \option{--min-vsize} can be
|
|
|
86 |
% changed by setting the environment variables \env{R\_NSIZE} and
|
|
|
87 |
% \env{R\_VSIZE} respectively, perhaps most conveniently in the file
|
|
|
88 |
% \file{.Renviron} or \file{\eqn{\sim}{~}/.Renviron}. There should no
|
|
|
89 |
% longer be any need to do so.
|
|
|
90 |
|
| 7350 |
hornik |
91 |
When using \code{\link{read.table}}, the memory requirements are in
|
|
|
92 |
fact higher than anticipated, because the file is first read in as one
|
|
|
93 |
long string which is then split again. Use \code{\link{scan}} if
|
|
|
94 |
possible in case you run out of memory when reading in a large table.
|
| 3076 |
pd |
95 |
}
|
| 11197 |
ripley |
96 |
|
|
|
97 |
\value{
|
|
|
98 |
(\code{mem.limits}) an integer vector giving the current settings of
|
|
|
99 |
the maxima, possibly \code{NA}.
|
|
|
100 |
}
|
|
|
101 |
|
| 3076 |
pd |
102 |
\seealso{
|
| 8872 |
pd |
103 |
\code{\link{gc}} for information on the garbage collector,
|
|
|
104 |
\code{\link{memory.profile}} for profiling the usage of cons cells.
|
| 11197 |
ripley |
105 |
#ifdef windows
|
| 12256 |
pd |
106 |
|
| 27447 |
ripley |
107 |
\code{\link[utils]{memory.size}} to monitor total memory usage,
|
|
|
108 |
\code{\link[utils]{memory.limit}} for the current limit.
|
| 11197 |
ripley |
109 |
#endif
|
| 3076 |
pd |
110 |
}
|
| 11197 |
ripley |
111 |
|
|
|
112 |
\note{
|
| 25260 |
hornik |
113 |
For backwards compatibility, options \option{--nsize} and
|
|
|
114 |
\option{--vsize} are equivalent to \option{--min-nsize} and
|
|
|
115 |
\option{--min-vsize}.
|
| 7422 |
ripley |
116 |
#ifdef windows
|
| 11197 |
ripley |
117 |
|
|
|
118 |
When using the \code{Rgui} console it is simplest to make a shortcut and
|
| 7422 |
ripley |
119 |
put these command-line flags at the end of the Target field.
|
| 11197 |
ripley |
120 |
#endif
|
| 7422 |
ripley |
121 |
}
|
| 11197 |
ripley |
122 |
|
| 3076 |
pd |
123 |
\examples{
|
| 11197 |
ripley |
124 |
# Start R with 10MB of heap memory and 500k cons cells, limit to
|
|
|
125 |
# 100Mb and 1M cells
|
| 3076 |
pd |
126 |
\dontrun{
|
| 7422 |
ripley |
127 |
## Unix
|
| 11197 |
ripley |
128 |
R --min-vsize=10M --max-vsize=100M --min-nsize=500k --max-nsize=1M
|
| 3076 |
pd |
129 |
}
|
|
|
130 |
}
|
| 7232 |
hornik |
131 |
\keyword{environment}
|