4

如何在代码中的某个点捕获对象的地址?例如:

NSString * aString = @"bla bla";
//what is the current address of aString. i.e to which address in memory does it currently point to
aString = @"la la la";
//what is the current address of aString.
4

2 回答 2

7

例子:

NSString *temp = @"123";

uintptr_t ptrAddress = (uintptr_t) temp;

NSLog(@"%@ %p %lu", temp, temp, ptrAddress);

安慰:

2013-07-11 11:51:20.796 asd[6474:907] 123 0x17985c 1546332

它也可能对您有用 - NSPointerArray (iOS 6+)

于 2013-07-11T08:53:46.287 回答
4

这很容易,只需执行以下操作:

NSLog(@"%p", aString);

那是打印指针的格式规范。

于 2013-07-11T08:34:23.063 回答