[R] Is there lazy copy in R?

tlumley at u.washington.edu tlumley at u.washington.edu
Wed Dec 16 01:33:21 CET 2009


On Tue, 15 Dec 2009, Peng Yu wrote:

> 2009/12/15  <tlumley at u.washington.edu>:
>> On Wed, 16 Dec 2009, Peng Yu wrote:
>>
>>> On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham <h.wickham at gmail.com>
>>> wrote:
>>>>>
>>>>> I don't understand what these addresses mean. Would you please help me
>>>>> understand it?
>>>>
>>>> Did you try reading the documentation?
>>>>
>>>>     When an object is traced any copying of the object by the C
>>>>     function ‘duplicate’ or by arithmetic or mathematical operations
>>>>     produces a message to standard output.  The message consists of
>>>>     the string ‘tracemem’, the identifying strings for the object
>>>>     being copied and the new object being created, and a stack trace
>>>>     showing where the duplication occurred.  ‘retracemem()’ is used to
>>>>     indicate that a variable should be considered a copy of a previous
>>>>     variable (e.g. after subscripting).
>>>
>>> "The message consists of the string ‘tracemem’, the identifying
>>> strings for the object being copied and the new object being created,
>>> and a stack trace showing where the duplication occurred."
>>>
>>> I tried to read the document before I posted, but wasn't be able to
>>> understand it, because there are multiple ways to parse it.
>>>
>>> To make sure that I understand, I rewrite the above sentence to the
>>> following. Is it correct?
>>>
>>> "The message consists of the string ‘tracemem’, the string indicating
>>> the object being copied,  the string indicating the new object being
>>> created, and a stack trace showing where the duplication occurred."
>>>
>>> I also didn't see a stack trace in my example. If I didn't see Martin
>>> Morgan's post, I will still be confused.
>>>
>>
>> The stack trace is there, it's just that it is empty because you aren't in a
>> function.
>>
>>> I thought that there should be only one coping. Why there are two lines?
>>>
>>> tracemem[0x05cf2798 -> 0x05cf2750]:
>>> tracemem[0x05cf2750 -> 0x05ed8ba0]:
>
> I still don't understand what the numbers after 'tracemem[' are. Could
> somebody please explain it?

They are the printed representations of the pointers to the objects on the R heap. In practice, they will be base-16 representations of  the memory addresses (though the C standard doesn't guarantee this).   The one before the -> is the address of the object being copied; the one after the -> is the address of the copy.   The point is to give names to each object, since they need not be R variables and may not have any other name.

In this trace you can see that the second copy is of the object created in the first copy.

            -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle


More information about the R-help mailing list