Re: set vs copy?
Re: set vs copy?
- Subject: Re: set vs copy?
- From: "Nigel Garvey" <email@hidden>
- Date: Wed, 15 Sep 2010 09:13:28 +0100
Shane Stanley wrote on Wed, 15 Sep 2010 08:38:57 +1000:
>Copy makes a complete copy of what a variable refers to, whereas set just
>makes another variable pointing to the same stuff in memory.
>
>For mutable classes like list, record and date, having more than one
>variable point to the same chunk of memory means that if you modify the
>contents of one of these variables, any others pointing to the same chunk of
>memory will also return the new value. This can be avoided, where necessary,
>by using copy to make an entirely separate, um, copy.
>
>For immutable classes like text, real, etc, the fact that more than one
>variable can point to the same chunk of memory is irrelevant, because the
>contents can't be modified once it's created anyway. So doing a copy in such
>cases is just wasting time and memory.
Chris Nebel told me on this list a few years ago that 'copy' only makes
copies of mutable objects. With immutable data, it behaves exactly the
same way as 'set'. The reason it takes slightly longer over it is that,
being 'copy', it has to work out first whether the objects are mutable or not.
I suspect, but don't know for sure, that this means 'copy' only
duplicates the _structures_ of mutable objects, which are pointers in
the same way that variables are. There's actually no need to duplicate
the values contained by those objects.
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden