[Rcpp-devel] Memory not mapped
Sameer D'Costa
sameerdcosta at gmail.com
Thu Feb 20 17:48:26 CET 2014
One thing you can do is start with a little test case and run multiple
times it to see if the segfault is really coming from where you think it
is.
/* test.cpp */
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
List entryexitclock( SEXP xts_obj_,int ent_col, int exit_col, double
clock_limit, int init_pos) {
// function takes in xts_obj_ (an xts object from R) and converts to a
NumericMatrix
Rcpp::NumericMatrix x(xts_obj_);
// Get the index and call v
DatetimeVector v(NumericVector(RObject(xts_obj_).attr("index")));
// The dimensions of rtn_xts are extracted
int nr = x.nrow();
List l;
return (l);
}
Then on the R side you can test it out
library(Rcpp)
library(xts)
sourceCpp("test.cpp")
n <- 10000
k <- xts(as.numeric(1:n), Sys.time()+1:n)
res <- lapply(1:10000, function(z) entryexitclock(k, 12, 12, 60*60,0))
This code does not seem to segfault for me using R 2.15.3 on Ubuntu with
Rcpp 0.10.4. Does it segfault for you?
If I were you I would keep adding code to the test example till it
segfaults reliably. If you do this one line at a time you will have a good
idea of which line is causing the segfault. Usually the "user error"
becomes apparent :). If you are unsure you could winnow down the test case
to a small reproducible test case that crashes reliably and then post it
to the list.
Regards
Sameer
On Thu, Feb 20, 2014 at 9:50 AM, Hideyoshi Maeda
<hideyoshi.maeda at gmail.com>wrote:
> Hi I am trying to run a function I created in Rcpp, which is then
> sourced/compiled and executed in R.
>
> The function is called "entryexitclock".
>
> and starts off as follows:
>
> #include <Rcpp.h>
> using namespace Rcpp;
>
> // [[Rcpp::export]]
> List entryexitclock( SEXP xts_obj_,int ent_col, int exit_col, double
> clock_limit, int init_pos) {
> // function takes in xts_obj_ (an xts object from R) and converts to a
> NumericMatrix
> Rcpp::NumericMatrix x(xts_obj_);
> // Get the index and call v
> DatetimeVector v(NumericVector(RObject(xts_obj_).attr("index")));
> // The dimensions of rtn_xts are extracted
> int nr = x.nrow();
>
> There is more code but I'm starting to doubt if its related to the rest of
> the code. I have a feeling it might be my use of SEXP but I'm not sure...
>
> The compilation works fine, however "sometimes" the code works and
> sometimes the code doesn't...
>
> The error when it doesn't is as follows:
>
>
> *** caught segfault ***
> address 0x11a9783c8, cause 'memory not mapped'
>
> Traceback:
> 1: .Primitive(".Call")(<pointer: 0x1044dde70>, xts_obj_, ent_col,
> exit_col, clock_limit, init_pos)
> 2: entryexitclock(k, 11, 12, 60 * 60, 0)
>
> Possible actions:
> 1: abort (with core dump, if enabled)
> 2: normal R exit
> 3: exit R without saving workspace
> 4: exit R saving workspace
>
> Any suggestions as to what I can do to make sure that this function works
> every time rather than just sometimes?
>
> HLM
>
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140220/590aa2b8/attachment.html>
More information about the Rcpp-devel
mailing list