Skip to content

Instantly share code, notes, and snippets.

@Alexander-Ignition
Last active June 6, 2024 07:31
Show Gist options
  • Save Alexander-Ignition/62a60b6435b624b7e1d095d7f9e6cbb1 to your computer and use it in GitHub Desktop.
Save Alexander-Ignition/62a60b6435b624b7e1d095d7f9e6cbb1 to your computer and use it in GitHub Desktop.
Swift struct max size
struct User {
typealias Ten<T> = (T, T, T, T, T, T, T, T, T, T)
let id: Int
let name: String
let storage: Ten<Ten<Ten<Ten<Ten<UInt64>>>>>?
}
func structMaxSize() {
print("MemoryLayout<User>.size:", MemoryLayout<User>.size)
let u = User(id: 0, name: "", storage: nil)
print("MemoryLayout<User>.size of value:", MemoryLayout<User>.size(ofValue: u))
let thread = Thread {
let u = User(id: 0, name: "", storage: nil) // Thread 10: EXC_BAD_ACCESS (code=2, address=0x17025c000)
print("MemoryLayout<User>.size of value:", MemoryLayout<User>.size(ofValue: u))
}
// thread.stackSize = 10 // Can't set stack size to a value lower than 16384 (requested 10)
print("thread.stackSize:", thread.stackSize)
thread.start()
}
@Alexander-Ignition
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment