[R] Protecting pointer; Rdefines.h

In-Sun Nam inam at man.ac.uk
Thu Jul 4 18:56:47 CEST 2002


Dear Mr. Lumley,

Many thanks for your reply; I am trying to change my existing C++ code to
this R comparable C++ code as it seems easier to call R funtion from the
latter set up (pg 27, Writing R extensions); Besides, I couldn't find any
example on using call_R. Ultimately, I want to call lsoda from my code to
solve differential equations.

This morning I was quite confused with the way that R handles pointers and
actual values, compared to that of C++. However, spending a day helped me a
bit.

Nonetheless, I wish that you may kindly clarify the concept of garbage
control; My main problem is that I do not have a clear definition of "R
heap".

1>
 For example, lets assume that an object "par" is a SEXP to be protected (pg
42; Writing R extensions);
however

tt = NUMERIC_POINTER(par)[0]

doesn't need to be. This was one thing that I did not quite understand why.
So it is because the righthand side is nothing more than a double?

2>
Another one is that
" It is a common mistake to believe that if you invoked PROTECT(p) at some
point then p is protected from then on, but that is not true once a new
object is assigned to p". (pg 29; Writing R extensions)

So I don't need to protect "par" again if I reassign

 NUMERIC_POINTER(par)[0]  = 2.0;

for example??


Thank you so much for your help.

In-Sun









----- Original Message -----
From: Thomas Lumley <tlumley at u.washington.edu>
To: In-Sun Nam <inam at man.ac.uk>
Cc: <R-help at stat.math.ethz.ch>
Sent: Thursday, July 04, 2002 5:19 PM
Subject: Re: [R] Protecting pointer; Rdefines.h


> On Thu, 4 Jul 2002, In-Sun Nam wrote:
>
> > Dear All,
> >
> > I want to protect a pointer instead of its value and hope that someone
can
> > confirm what I am thinking is okay.
> >
> > If I want to assign a pointer "DTIME" as "OrigDTime" then should I do
> >
> > PROTECT(*OrigDTime = NUMERIC_POINTER(*DTime))
> >
>
> At least one of us is confused.  PROTECT is only relevant for objects
> allocated on the R heap (eg with allocVector, allocString), and prevents
> the location on the heap from being garbage collected.
>
> NUMERIC_POINTER() applies to R objects (SEXPs) that are numeric vectors,
> and returns an ordinary double * that doesn't need (and can't use)
> PROTECTion, so  your suggested code is almost certainly wrong.
>
> If you give more detail as to what you are really trying to do someone may
> be able to help.
>
> -thomas
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list