Can some help in explaining/understanding the memory structure of Tuple like
a. where tuple is created heap/stack ?.
b. what happens when a tuple is copied ?.
c. any detailed article/reference would be a great help.
Can some help in explaining/understanding the memory structure of Tuple like
a. where tuple is created heap/stack ?.
b. what happens when a tuple is copied ?.
c. any detailed article/reference would be a great help.
tuples are exactly like structs, specially tuple structs, but they are structural types instead of nominal types (meaning all tuples with the same components are considered the same type, while structs with different names, even the definitions are the same, are different types ). so everything you know about structs applies to tuples.
static TUPLE1: (i32, i32) = (1, 2); // in static memory
let tuple2 = (3, 4); // on the stack
let tuple3 = Box::new((5, 6)); // on the heap
And if you were curious how tuples are arranged in memory (i.e. which elements go where), it's undefined. The compiler rearranges elements to minimize size.