[R] "Memory not mapped" when using .C, problem in Mac but not in Linux

William Dunlap wdunlap at tibco.com
Wed Oct 13 18:54:33 CEST 2010


This often happens when your C code uses memory that
it did not allocate, particularly when it reads or
writes just a little beyond the end of a memory block.
On some platforms or if you are lucky there is unused
memory between blocks of allocated memory and you don't
see a problem.  Other machines may pack allocated memory
blocks more tightly and writing off the end of an array
corrupts another array, leading to the program crashing.
(Or reading off the end of an array may pick up data from
the next array, which leads to similar crashes later on.)
You may also be reading memory which has never been written
to, hence you are using random data, which could corrupt
things.

Use a program like valgrind (on Linux, free) or Purify (on
various platforms, but pricy) to detect memory misuse
in C/C++ code.  As long as your code isn't #ifdef'ed for
various platforms, you can use valgrind to detect and fix
memory misuse on Linux and you will find that overt
problems on other platforms will go away.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of David
> Sent: Wednesday, October 13, 2010 6:47 AM
> To: r-help at r-project.org
> Subject: [R] "Memory not mapped" when using .C,problem in Mac 
> but not in Linux
> 
> Hello,
> 
> I am aware this may be an obscure problem difficult to advice 
> about, but
> just in case... I am calling a C function from R on an iMac 
> (almost shining:
> bought by my institution this year) and gives a "memory not 
> mapped" error.
> 
> Nevertheless, exactly the same code runs without problem in a powerful
> computer using SuSE Linux, but also on my laptop of 2007, 32 
> bits, 2 GB RAM,
> running Ubuntu. My supervisor says that he can run my code on 
> his iMac (a
> bit older than mine) without problem.
> 
> I have upgraded to the latest version of R, and I have tried 
> compiling the C
> code with the latest version of gcc (obtained from MacPorts), 
> but the error
> persists.
> 
> Any ideas?
> 
> Thank you very much in advance,
> 
> David
> Can you please Cc to me any replies, just in case I may miss 
> any of them
> among the whole amount of emails :-) ?
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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