Skip to content
Prev 22647 / 398502 Next

Q: replacing elements in an array

On Tue, 13 Aug 2002, Laurent Gautier wrote:

            
I don't think so.  See do_subassign and descendants.  It contains

    /* If there are multiple references to an object we must */
    /* duplicate it so that only the local version is mutated. */
    /* This will duplicate more often than necessary, but saves */
    /* over always duplicating. */
    /* FIXME: shouldn't x be protected? */

    if (NAMED(CAR(args)) == 2)
	x = SETCAR(args, duplicate(CAR(args)));

Now coercion can force a copy, but starting from a numeric array I think
your example does not duplicate.  And I can prove it:
[1] 20000128
[1] 29028352
[1] 29028352

so there was never a second copy.
See above.  Do your own experiments / reading of code?