diff --git a/ChangeLog b/ChangeLog index e373a96a4..571e17073 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-04-25 Dirk Eddelbuettel + + * inst/include/Rcpp/sugar/functions/sample.h: Replace R_alloc() with + a standard vector allocation to reduce memory consumption in sample + 2020-04-16 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll minor version diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 3c99425c5..9604643cf 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -38,6 +38,11 @@ \item The exceptions test is now partially skipped on Solaris as it already is on Windows (Dirk in \ghpr{1065}). } + \item Changes in Rcpp Sugar: + \itemize{ + \item Two \code{sample()} objects are now standard vectors and not + \code{R_alloc} created (Dirk in \ghpr{1075} fixing \ghpr{1074}). + } } } diff --git a/inst/include/Rcpp/sugar/functions/sample.h b/inst/include/Rcpp/sugar/functions/sample.h index 9f4817b1c..50bd63813 100644 --- a/inst/include/Rcpp/sugar/functions/sample.h +++ b/inst/include/Rcpp/sugar/functions/sample.h @@ -348,7 +348,7 @@ inline Vector EmpiricalSample(int n, int size, bool replace, bool one_ba return ans; } - int* x = reinterpret_cast(R_alloc(n, sizeof(int))); + IntegerVector x = no_init(n); for (int i = 0; i < n; i++) { x[i] = i; } @@ -378,7 +378,7 @@ inline Vector EmpiricalSample(int size, bool replace, const Vector return ans; } - int* x = reinterpret_cast(R_alloc(n, sizeof(int))); + IntegerVector x = no_init(n); for (int i = 0; i < n; i++) { x[i] = i; }