Skip to content

Commit

Permalink
Improve error message when memory is exhausted (macOS users may not b…
Browse files Browse the repository at this point in the history
…e aware

of the default limit on vector heap).


git-svn-id: https://svn.r-project.org/R/trunk@85646 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed Nov 29, 2023
1 parent 75cd311 commit 459492b
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/main/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2158,21 +2158,40 @@ attribute_hidden SEXP do_gc(SEXP call, SEXP op, SEXP args, SEXP rho)
return value;
}


NORET static void mem_err_heap(R_size_t size)
{
errorcall(R_NilValue, _("vector memory exhausted (limit reached?)"));
if (R_MaxVSize == R_SIZE_T_MAX)
errorcall(R_NilValue, _("vector memory exhausted"));
else {
double l = R_GetMaxVSize() / 1024.0;
const char *unit = "Kb";

if (l > 1024.0*1024.0) {
l /= 1024.0*1024.0;
unit = "Gb";
} else if (l > 1024.0) {
l /= 1024.0;
unit = "Mb";
}
errorcall(R_NilValue,
_("vector memory limit of %0.1f %s reached, see mem.maxVSize()"),
l, unit);
}
}


NORET static void mem_err_cons(void)
{
errorcall(R_NilValue, _("cons memory exhausted (limit reached?)"));
if (R_MaxNSize == R_SIZE_T_MAX)
errorcall(R_NilValue, _("cons memory exhausted"));
else
errorcall(R_NilValue,
_("cons memory limit of %llu nodes reached, see mem.maxNSize()"),
(unsigned long long)R_MaxNSize);
}

NORET static void mem_err_malloc(R_size_t size)
{
errorcall(R_NilValue, _("memory exhausted (limit reached?)"));
errorcall(R_NilValue, _("memory exhausted"));
}

/* InitMemory : Initialise the memory to be used in R. */
Expand Down

0 comments on commit 459492b

Please sign in to comment.