[R] .Call function crashes initializing matrix
William Dunlap
wdunlap at tibco.com
Sun Apr 11 02:35:55 CEST 2010
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Erik Wright
> Sent: Saturday, April 10, 2010 3:23 PM
> To: r help
> Subject: [R] .Call function crashes initializing matrix
>
> Hello,
>
> I have a C function that I call from R using .Call. I
> recently discovered a bug in my code, and I am not sure if it
> is a problem with what I am doing in C or if it has something
> to do with my use of .Call.
>
> I have narrowed my problem down to these two C statements:
> int size = 5000;
> double matrix[size][size];
>
> When I run this in R it crashes, with this message:
> *** caught segfault ***
> address 0xb4141d70, cause 'memory not mapped'
You may be overflowing the stack. Allocate
the space for 'matrix' with the allocation
functions described in section 5.9 of "Writing
R Extensions". They allocate space on the 'heap',
which has much more space than the stack (where
space for 'automatic' variables is allocated).
Typical stack sizes are on the order of few
megabytes and typical heap sizes are in the gigabytes.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
>
> It has no problem when size is smaller, like 50. Any idea
> what is going on?
>
> Thanks!,
> Erik
>
>
> sessionInfo()
> R version 2.10.1 (2009-12-14)
> i386-apple-darwin9.8.0
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods
> [7] base
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list