Created
April 27, 2020 06:29
-
-
Save seka/6f1a79273638d34d5f5cfda6b0a87a37 to your computer and use it in GitHub Desktop.
NSDataとCFDataの関係をメモ (Toll-Free Bridge)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
var data: NSData = NSData.init(bytes: "Hello, World!", length: 13) | |
withUnsafePointer(to: data) { | |
print("value \(String(describing: data)) has address: \($0)") | |
} | |
var cfData: CFData = data | |
withUnsafePointer(to: cfData) { | |
print("value \(String(describing: cfData)) has address: \($0)") | |
} | |
var ptr = data.bytes.assumingMemoryBound(to: UInt8.self) | |
var cfDataRef: CFTypeRef = CFDataCreate(kCFAllocatorDefault, ptr, 13) | |
withUnsafePointer(to: cfDataRef) { | |
print("value \(String(describing: cfDataRef)) has address: \($0)") | |
} | |
/** | |
* 自分の環境だと | |
* str value {length = 13, bytes = 0x48656c6c6f2c20576f726c6421} has address: 0x00007ffeeaee9b10 | |
* str value {length = 13, bytes = 0x48656c6c6f2c20576f726c6421} has address: 0x00007ffeeaee9b10 | |
* str value {length = 13, bytes = 0x48656c6c6f2c20576f726c6421} has address: 0x00007ffeeaee9b10 | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nsdata -> cfdata にキャストしても、メモリは同じアドレスを参照しているように見える