Does anyone know if there is a way to have a C-like array inside a struct ?
I would like to have the memory for the array allocated alongside the struct, not somewhere else on the heap. The goal is to avoid the extra memory allocation because of the array.
It is fine if the array can not grow like Swift array, of course.
struct MyStruct {
var myValue: Int
var myArray: [Int8] = .init(repeating: 0, count: 100)
// ^ here, I would like the items of myArray allocated inside MyStruct
}
Tuples are the way to do it. There have been a number of proposals for alternatives, such as Proposal: Contiguous Variables (A.K.A. Fixed Sized Array Type). I don't believe there is a profound reason that it isn't present, but it causes trickiness in the type system, and just generally has not been worked through at this time.