Created
January 3, 2018 14:23
-
-
Save anonymous/fd7d6dad3880c3a60210cd4b655cbaa8 to your computer and use it in GitHub Desktop.
Snippet from https://play.nim-lang.org
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
| type Discriminator = enum | |
| d1, d2, d3 | |
| type Variant = object | |
| # 39 bytes --> 40 bytes | |
| f1: int32 # 4 bytes | |
| case discrim: Discriminator # 1 byte | |
| of d1: | |
| f2: float64 # 8 bytes | |
| f3: float64 # 8 bytes | |
| f4: float64 # 8 bytes | |
| f5: float64 # 8 bytes | |
| of d2: | |
| f6: int8 # 1 byte | |
| f7: int8 # 1 byte | |
| else: | |
| discard | |
| type NonVariantD2 = object | |
| # 6 byte -> 8 byte | |
| f1: int32 | |
| f6: int8 | |
| f7: int8 | |
| let nv = NonVariantD2() | |
| let v1 = Variant(discrim: d1) | |
| let v2 = Variant(discrim: d2) | |
| let v3 = Variant(discrim: d3) | |
| echo sizeof(nv) | |
| echo sizeof(v1) | |
| echo sizeof(v2) | |
| echo sizeof(v3) | |
| echo sizeof(1.int32) | |
| echo sizeof(d1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment