• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: copy and mutableCopy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: copy and mutableCopy


  • Subject: Re: copy and mutableCopy
  • From: Dave <email@hidden>
  • Date: Sun, 27 Apr 2014 12:06:04 +0100

Hi,

> Apart from intellectual curiosity were you actually looking for this for a reason?


A bit of boh really, I’ve been profiling my App and the type of behaviour I describe seems to be occurring. When I wrote:

myData = [self newData];
myNewData = [myData copy];
[myData release];					//If Non-ARC, removed if ARC, I am using ARC.

I put a TO DO against it to try and check how much actual copying of data (meaning more memory usage) was actually occurring, but it seems in most (if not all) cases no actual data is being copied.

I was quite prepared to take the hit from the copy anyway, but it seems it doesn't actually do any.

I realize this may change for any number of reasons, but right now, on the config I am testing against, no data is being copied. I think it was in an Apple Developer Videoand Keynote presentation from when the iPhone SDK was first introduced or maybe V2 or V3 iOS SDK, but but I could be wrong.

Dave


On 27 Apr 2014, at 11:46, Roland King <email@hidden> wrote:

> ok but you can't rely on any of this behaviour, because the only defined interface is copy (or copyWithZone) and mutableCopy (or rather mutableCopyWithZone). If NSMutableData is smart enough to do copy-on-write then that's great.
>
> I've certainly never seen any apple documentation which discusses the details of how objects do and don't copy, perhaps you were reading someone else's analysis.
>
> Apart from intellectual curiosity were you actually looking for this for a reason?
>
> On 27 Apr, 2014, at 6:32 pm, Dave <email@hidden> wrote:
>
>> Hi,
>>
>> Yes, I can see there are no guarantees and if is *has* to copy the object it will, but it has some optimisations, take this for example:
>>
>> -(NSData*) newData
>> {
>> NSData*  myData;
>>
>> myData = [[NSData alloc] init];
>> //Add data to myData
>>
>> return myData;
>> }
>>
>> -(void) someMethod
>> {
>> NSData*  myData;
>> NSData*  myNewData;
>>
>> myData = [self newData];
>> myNewData = [myData copy];
>>
>> [myData release];
>>
>> //Do something the myNewData
>>
>> }
>>
>> I think it said, in cases like this, no real data would be copied. It also said something like, the same would be true if it were using NSMutableData, as long as “myData” is NOT mutated before it is released.
>>
>> It’s these types of cases I’m talking about, I realize that if objects start mutating then physical copies need to be made in some cases. it’s just it doesn't happen automatically just because you have invoked copy or mutableCopy - physical copies only occur IF they need to.
>>
>> Thanks
>> Dave
>>
>> On 27 Apr 2014, at 10:00, Dave <email@hidden> wrote:
>>
>>> Hi All,
>>>
>>> A long time back, I remember reading something about the way in which copy and mutableCopy are implemented. I think basically it said that:
>>>
>>> someObject = [someOtherObject copy];
>>>
>>> or
>>>
>>> someObject = [someOtherObject mutableCopy];
>>>
>>> Wouldn’t necessarily allocate any extra data storage. I’ve been searching for it to refresh my memory, but I can’t see to find it anywhere. Does anyone know if this document or something like it exists somewhere?
>>>
>>> Thanks a lot
>>> Dave
>>>
>>>
>>> _______________________________________________
>>>
>>> Cocoa-dev mailing list (email@hidden)
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >copy and mutableCopy (From: Dave <email@hidden>)
 >Re: copy and mutableCopy (From: Dave <email@hidden>)
 >Re: copy and mutableCopy (From: Roland King <email@hidden>)

  • Prev by Date: Re: copy and mutableCopy
  • Next by Date: Re: copy and mutableCopy
  • Previous by thread: Re: copy and mutableCopy
  • Next by thread: Re: copy and mutableCopy
  • Index(es):
    • Date
    • Thread