Hi,
I assume according to "Cocoa design patterns" book i'm reading that the retain function is implemented using something like this :
- (int)retainCount
// Returns the receiver's current reference count
{
int result = 1; // receiver not in table, its count is 1
void *tableValue = NSMapGet(
[[self class] _myRefCountMapTable], self);
if(NULL != tableValue )
{ // if receiver is in table, its count is the value stored
result = (int)tableValue;
}
return result;
}
- (id)retain
// Increases the receiver's reference count
{
// store the increased value in the table
NSMapInsert([[self class] _myRefCountMapTable], self,
(void *)([self retainCount] + 1));
return self;
}
As the example imply every reference object has the same self member. How does that happen ? maybe I don't understand the meaning of self - I though it's like "this" in C++.
If I just use assignment operator (A=B) Does it copy the pointer(self) and that's it ? I though it would use "copywithzone" and it's relatives and the "self" members won't be equal. Moreover, I though copywithzone is like copy constructor in c++.
I guess i'm confusing between the 2 worlds.