Skip to content

[Rcpp-devel] R Memory Management and RInside

4 messages · Whit Armstrong, Dirk Eddelbuettel, gershon bialer

#
Hi,

I'm trying to use RInside, but I get the seg fault show below. Does
R's memory management somehow interfere with   the C++ standard
library memory management? What could be causing this?

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000018
0x0000000103b630fe in Rf_allocVector (type=24, length=262144) at memory.c:2423
2423		    SNAP_NODE(s, R_GenHeap[LARGE_NODE_CLASS].New);
(gdb) bt
#0  0x0000000103b630fe in Rf_allocVector (type=24, length=262144) at
memory.c:2423
#1  0x0000000103b638fe in R_alloc (nelem=4300886016, eltsize=262144)
at memory.c:1976
#2  0x0000000103b746dd in vmmin (n0=1606401184, b=0x7fff5fbfbca0,
Fmin=0x7fff5fbfbca0, fminfn=0x7fff5fbfbca0, fmingr=0x7fff5fbfbca0,
maxit=1606401184, trace=1, mask=0x103840328,
abstol=6.9532229750197531e-310, reltol=6.9532229750197531e-310,
nREPORT=10, ex=0x0, fncount=0x7fff5fbfbcec, grcount=0x7fff5fbfbce8,
fail=0x1036d41b0) at optim.c:513
#3  0x00000001027e8d09 in VR_dovm ()
#4  0x00000001000d5a17 in do_dotCode ()
#5  0x0000000100101a8a in Rf_eval ()
#6  0x000000010010414a in do_set ()
#7  0x000000010010191c in Rf_eval ()
#8  0x0000000100103172 in do_begin ()
#9  0x000000010010191c in Rf_eval ()
#10 0x0000000100105cfa in Rf_applyClosure ()
#11 0x000000010014626b in Rf_usemethod ()
#12 0x000000010014659e in do_usemethod ()
#13 0x000000010010191c in Rf_eval ()
#14 0x0000000100105cfa in Rf_applyClosure ()
#15 0x0000000100101b48 in Rf_eval ()
#16 0x000000010010414a in do_set ()
#17 0x000000010010191c in Rf_eval ()
#18 0x0000000100102442 in do_eval ()
#19 0x00000001000fa93c in bcEval ()
#20 0x00000001001016c3 in Rf_eval ()
#21 0x0000000100105cfa in Rf_applyClosure ()
#22 0x00000001000fa809 in bcEval ()
#23 0x00000001001016c3 in Rf_eval ()
#24 0x0000000100105cfa in Rf_applyClosure ()
#25 0x0000000100101b48 in Rf_eval ()
#26 0x00000001000bd2e7 in protectedEval ()
#27 0x00000001000bdb80 in R_ToplevelExec ()
#28 0x00000001000bdbfa in R_tryEval ()
#29 0x00000001000085fa in RInside::parseEval ()
#30 0x000000010000964d in RInside::parseEval ()
#31 0x0000000100028d78 in PosixTestClient::PosixTestClient ()
#32 0x00000001000299d8 in main ()
#
looks like you did something bad with a pointer, but it's hard to
know without seeing your code.

why don't you run w/ valgrind, it might help you locate the problem.

like this:
warmstrong at krypton:~$ R --debugger=valgrind
==28550== Memcheck, a memory error detector
==28550== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==28550== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==28550== Command: /usr/lib/R/bin/exec/R --no-save --no-restore --silent
==28550==

        
On Tue, Mar 6, 2012 at 2:08 AM, gershon bialer <gershon.bialer at gmail.com> wrote:
#
On 5 March 2012 at 23:08, gershon bialer wrote:
| Hi,
| 
| I'm trying to use RInside, but I get the seg fault show below. Does
| R's memory management somehow interfere with   the C++ standard
| library memory management? What could be causing this?

Nobody can tell, really, as you posted no code. Please do.

There are over as dozen small, self-contained examples in the RInside sources
that you can use as a starting point.

Also, do not forget that you canot have more than precisely one instance of
RInside in your code due to the way R is organised (single-threaded etc).

Dirk

| 
| Program received signal EXC_BAD_ACCESS, Could not access memory.
| Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000018
| 0x0000000103b630fe in Rf_allocVector (type=24, length=262144) at memory.c:2423
| 2423		    SNAP_NODE(s, R_GenHeap[LARGE_NODE_CLASS].New);
| (gdb) bt
| #0  0x0000000103b630fe in Rf_allocVector (type=24, length=262144) at
| memory.c:2423
| #1  0x0000000103b638fe in R_alloc (nelem=4300886016, eltsize=262144)
| at memory.c:1976
| #2  0x0000000103b746dd in vmmin (n0=1606401184, b=0x7fff5fbfbca0,
| Fmin=0x7fff5fbfbca0, fminfn=0x7fff5fbfbca0, fmingr=0x7fff5fbfbca0,
| maxit=1606401184, trace=1, mask=0x103840328,
| abstol=6.9532229750197531e-310, reltol=6.9532229750197531e-310,
| nREPORT=10, ex=0x0, fncount=0x7fff5fbfbcec, grcount=0x7fff5fbfbce8,
| fail=0x1036d41b0) at optim.c:513
| #3  0x00000001027e8d09 in VR_dovm ()
| #4  0x00000001000d5a17 in do_dotCode ()
| #5  0x0000000100101a8a in Rf_eval ()
| #6  0x000000010010414a in do_set ()
| #7  0x000000010010191c in Rf_eval ()
| #8  0x0000000100103172 in do_begin ()
| #9  0x000000010010191c in Rf_eval ()
| #10 0x0000000100105cfa in Rf_applyClosure ()
| #11 0x000000010014626b in Rf_usemethod ()
| #12 0x000000010014659e in do_usemethod ()
| #13 0x000000010010191c in Rf_eval ()
| #14 0x0000000100105cfa in Rf_applyClosure ()
| #15 0x0000000100101b48 in Rf_eval ()
| #16 0x000000010010414a in do_set ()
| #17 0x000000010010191c in Rf_eval ()
| #18 0x0000000100102442 in do_eval ()
| #19 0x00000001000fa93c in bcEval ()
| #20 0x00000001001016c3 in Rf_eval ()
| #21 0x0000000100105cfa in Rf_applyClosure ()
| #22 0x00000001000fa809 in bcEval ()
| #23 0x00000001001016c3 in Rf_eval ()
| #24 0x0000000100105cfa in Rf_applyClosure ()
| #25 0x0000000100101b48 in Rf_eval ()
| #26 0x00000001000bd2e7 in protectedEval ()
| #27 0x00000001000bdb80 in R_ToplevelExec ()
| #28 0x00000001000bdbfa in R_tryEval ()
| #29 0x00000001000085fa in RInside::parseEval ()
| #30 0x000000010000964d in RInside::parseEval ()
| #31 0x0000000100028d78 in PosixTestClient::PosixTestClient ()
| #32 0x00000001000299d8 in main ()
| 
| -- 
| ---------------------
| Gershon Bialer
| _______________________________________________
| 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
#
Hi,

I figured out the bug. I'm on the mac, and I had recompiled R and my
application with GCC, but I had still had a bunch of libraries, which
had been built in LLVM. I suppose the issue with LLVM relates to how
it does memory management.

Thanks
On Tue, Mar 6, 2012 at 7:11 AM, Dirk Eddelbuettel <edd at debian.org> wrote: