Friday, June 23, 2017

Swift’s MemoryLayout: size and stride

Russ Bishop:

This might surprise you: the size of some types can be zero but the stride will always be at least 1 byte. Having types take up at least 1 byte means you don't need a bunch of special casing everywhere you deal with memory to avoid calling malloc(0). This does mean an array of 100 zero size types allocates 100 bytes that are never read or written.

Comments RSS · Twitter

Leave a Comment