Skip to content

Instantly share code, notes, and snippets.

@palimondo
Created March 14, 2017 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palimondo/ffec7c42dbc97261d9ca9fdecc8a0614 to your computer and use it in GitHub Desktop.
Save palimondo/ffec7c42dbc97261d9ca9fdecc8a0614 to your computer and use it in GitHub Desktop.
Additions to dump the memory layout of indirect enums.
enum List<Element> {
case End
indirect case Node(Element, List<Element>)
}
struct ManyListEnumHolder<Element> {
var a: List<Element>
var b: List<Element>
var c: List<Element>
var d: List<Element>
var e: List<Element>
}
dumpAndOpenGraph(dumping: ManyListEnumHolder<Int>(a: .End, b: .Node(1, .End), c: .Node(2, .Node(3, .End)), d: .Node(4, .Node(5, .Node(6, .End))), e: .Node(7, .Node(8, .Node(9, .Node(10, .End))))), maxDepth: 5, filename: "Many List enum")
indirect enum Tree<Element: Comparable> {
case Empty
case Node(Tree<Element>,Element,Tree<Element>)
}
struct ManyTreeEnumHolder<Element> where Element : Comparable {
var a: Tree<Element>
var b: Tree<Element>
var c: Tree<Element>
var d: Tree<Element>
var e: Tree<Element>
}
dumpAndOpenGraph(dumping: ManyTreeEnumHolder<Int>(a: .Empty, b: .Node(.Empty, 0x999999, .Empty), c: .Node(.Node(.Empty, 0x111111, .Empty), 0x222222, .Empty), d: .Node(.Empty, 0x333333, .Node(.Empty, 0x444444, .Empty)), e: .Node(.Node(.Empty, 0x555555, .Empty), 0x666666, .Node(.Empty, 0x777777, .Empty))), maxDepth: 5, filename: "Many Tree enum")
@palimondo
Copy link
Author

Added to the main.swift from https://github.com/mikeash/memorydumper2

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