←back to thread

146 points returningfory2 | 1 comments | | HN request time: 0s | source
Show context
lordnacho ◴[] No.43645689[source]
Does the niche optimization require the compiler to know things about the type? So that only certain specializations will work?

Also, how do I get some code to do the memory layout vizualizer, perhaps one that is a bit more advanced and knows what pointers are?

replies(1): >>43645823 #
pornel ◴[] No.43645823[source]
Internally the compiler tracks what "niches" exist in types, like minimum and maximum valid values, and takes the unused values for enum tags.

One thing it can't use is padding in structs, because references to individual fields must remain valid, and they don't guarantee that padding will be preserved.

replies(2): >>43645982 #>>43646104 #
1. ◴[] No.43645982[source]