Reputation: 521
I want to ask which is faster:
Making a new class object using alloc+init
or making a Copy
of the existing class object?
edited:
I was reading the prototype pattern and I got this query. In prototype pattern, we make a clone or copy of the existing object.
So in which case copy is faster than alloc?
Upvotes: 0
Views: 208
Reputation: 125007
The answer, of course, is it depends on what kind of object you're dealing with. For immutable objects such as NSString, calling -copy
really only retains the original object. On the other hand, one can guess that copying an instance of NSMutableString involves both creating a new object and copying the data from the original object, and in such cases copying would obviously take longer than simply creating a new, empty object.
Upvotes: 1