Skip to content

Commit bb6017c

Browse files
authored
Merge pull request #1075 from RcppCore/bugfix/1074
Use an explicit vector rather than R_alloc in sample
2 parents 4954e56 + 24f8d05 commit bb6017c

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-04-25 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/sugar/functions/sample.h: Replace R_alloc() with
4+
a standard vector allocation to reduce memory consumption in sample
5+
16
2020-04-16 Dirk Eddelbuettel <[email protected]>
27

38
* DESCRIPTION (Version, Date): Roll minor version

inst/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
\item The exceptions test is now partially skipped on Solaris as
3939
it already is on Windows (Dirk in \ghpr{1065}).
4040
}
41+
\item Changes in Rcpp Sugar:
42+
\itemize{
43+
\item Two \code{sample()} objects are now standard vectors and not
44+
\code{R_alloc} created (Dirk in \ghpr{1075} fixing \ghpr{1074}).
45+
}
4146
}
4247
}
4348

inst/include/Rcpp/sugar/functions/sample.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ inline Vector<INTSXP> EmpiricalSample(int n, int size, bool replace, bool one_ba
348348
return ans;
349349
}
350350

351-
int* x = reinterpret_cast<int*>(R_alloc(n, sizeof(int)));
351+
IntegerVector x = no_init(n);
352352
for (int i = 0; i < n; i++) {
353353
x[i] = i;
354354
}
@@ -378,7 +378,7 @@ inline Vector<RTYPE> EmpiricalSample(int size, bool replace, const Vector<RTYPE>
378378
return ans;
379379
}
380380

381-
int* x = reinterpret_cast<int*>(R_alloc(n, sizeof(int)));
381+
IntegerVector x = no_init(n);
382382
for (int i = 0; i < n; i++) {
383383
x[i] = i;
384384
}

0 commit comments

Comments
 (0)