如何在我的代碼中捕獲某個對象的地址? 例如:Objective-C >>在內存中捕獲對象地址
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.
如何在我的代碼中捕獲某個對象的地址? 例如:Objective-C >>在內存中捕獲對象地址
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.
實施例:
NSString *temp = @"123";
uintptr_t ptrAddress = (uintptr_t) temp;
NSLog(@"%@ %p %lu", temp, temp, ptrAddress);
控制檯:
2013年7月11日11:51:20.796 ASD [6474:907] 123 0x17985c 1546332
它也可以是對你有用 - NSPointerArray(iOS 6+)
這是相當容易的,只是做:
NSLog(@"%p", aString);
這是一個打印指針的格式規範。
謝謝! 「p」後面的類型是什麼?讓我們說,我想保持在某個地方,而不是僅僅記錄它? –
%p是指針,並以十六進制打印 – Andrea
這是...謝謝! –