Created
June 29, 2016 17:03
-
-
Save mikeash/687e377f2b08f8f10d48cef1af122076 to your computer and use it in GitHub Desktop.
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 Darwin | |
struct S { | |
var whatever: AnyObject? = nil | |
mutating func stuff() { | |
withUnsafePointer(&whatever, { | |
for offset in 0.stride(to: 128, by: sizeof(AnyObject.self)) { | |
let ptr = UnsafePointer<UInt8>($0) - offset | |
if malloc_size(ptr) > 0 { | |
print(ptr) | |
let obj = unsafeBitCast(ptr, AnyObject.self) | |
print("I'm in an object of type \(obj.dynamicType)") | |
break | |
} | |
} | |
}) | |
} | |
} | |
class C { | |
var a = 42 | |
var b = 1.1 | |
var s = S() | |
} | |
let c = C() | |
c.s.stuff() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment