Re: [Rd] Memory allocation in C/C++ vs R?

2010-05-09 Thread Andrew Runnalls
Dominick, On 30/04/10 18:40, Dominick Samperi wrote: Just to be sure that I understand, are you suggesting that the R-safe way to do things is to not use STL, and to not use C++ memory management and exception handling? How can you leave a function in an irregular way without triggering a

Re: [Rd] Memory allocation in C/C++ vs R?

2010-05-01 Thread Romain Francois
Simon, Le 30/04/10 20:12, Simon Urbanek a écrit : Dominick, On Apr 30, 2010, at 1:40 PM, Dominick Samperi wrote: Just to be sure that I understand, are you suggesting that the R-safe way to do things is to not use STL, and to not use C++ memory management and exception handling? How can

Re: [Rd] Memory allocation in C/C++ vs R?

2010-05-01 Thread Dominick Samperi
On Sat, May 1, 2010 at 5:02 AM, Romain Francois romain.franc...@dbmail.com wrote: Simon, Le 30/04/10 20:12, Simon Urbanek a écrit : Thank you for these nuggets of information. It might be beneficial to promote them to some notes in the Interfacing C++ code section of WRE. The manual is also

Re: [Rd] Memory allocation in C/C++ vs R?

2010-04-30 Thread Prof Brian Ripley
On Fri, 30 Apr 2010, Dominick Samperi wrote: The R docs say that there are two methods that the C programmer can allocate memory, one where R automatically frees the memory on return from .C/.Call, and the other where the user takes responsibility for freeing the storage. Both methods involve

Re: [Rd] Memory allocation in C/C++ vs R?

2010-04-30 Thread Simon Urbanek
Brian's answer was pretty exhaustive - just one more note that is indirectly related to memory management: C++ exception handling does interfere with R's error handling (and vice versa) so in general STL is very dangerous and best avoided in R. In addition, remember that regular local object

Re: [Rd] Memory allocation in C/C++ vs R?

2010-04-30 Thread Dominick Samperi
Simon, Just to be sure that I understand, are you suggesting that the R-safe way to do things is to not use STL, and to not use C++ memory management and exception handling? How can you leave a function in an irregular way without triggering a seg fault or something like that, in which case there

Re: [Rd] Memory allocation in C/C++ vs R?

2010-04-30 Thread Simon Urbanek
Dominick, On Apr 30, 2010, at 1:40 PM, Dominick Samperi wrote: Just to be sure that I understand, are you suggesting that the R-safe way to do things is to not use STL, and to not use C++ memory management and exception handling? How can you leave a function in an irregular way without

Re: [Rd] Memory allocation in C/C++ vs R?

2010-04-30 Thread Dominick Samperi
Thanks for the clarification Simon, I think it is safe (R-safe?) to say that if there are no exceptions or errors on either side, then it is highly likely that everything is fine. When there are errors or exceptions, it is probably NOT safe to try to recover. Better to terminate the R session,

Re: [Rd] Memory allocation in C/C++ vs R?

2010-04-30 Thread Simon Urbanek
Dominick, On Apr 30, 2010, at 2:51 PM, Dominick Samperi wrote: Thanks for the clarification Simon, I think it is safe (R-safe?) to say that if there are no exceptions or errors on either side, then it is highly likely that everything is fine. I think so - at least on the exceptions

Re: [Rd] Memory allocation in C/C++ vs R?

2010-04-30 Thread Dominick Samperi
Indeed. As I said, using heap objects (explicit initialization) does solve that issue, but you have to be again wary of other libraries which may still use static initializers. I just did a little test and found, in the case of gcc/g++, that a main C main program linked with a C++ library

[Rd] Memory allocation in C/C++ vs R?

2010-04-29 Thread Dominick Samperi
The R docs say that there are two methods that the C programmer can allocate memory, one where R automatically frees the memory on return from .C/.Call, and the other where the user takes responsibility for freeing the storage. Both methods involve using R-provided functions. What happens when