The topic of pointers vs. slices vs. array (etc.) comes up frequently. What to use when or how they compare to alternatives in other languages. I made this cheat sheet in an attempt to visualize the various “container” type in Odin. Maybe it helps.
Similarly the concept of strings as non-owning types and UTF-8 by convention tends to cause some confusion. Also how do they relate to ‘runes’? Once again, maybe a little visualization can help.
(It seems I can only embed one image as a new user so here is a link to the image for now. Maybe I can edit the post later to add the image directly).
9 Likes
Looks great! I was able to edit your post and embed the image as an admin 
3 Likes
One important thing also, is that dynamic arrays aren’t “Copyable”. If you do copy it and mutate one of them, the other one becomes invalid.
2 Likes
For anyone wondering why this is the case:
Raw_Dynamic_Array :: struct {
data: rawptr,
len: int,
cap: int,
allocator: Allocator,
}
len
and cap
are both fields on the dynamic array, and if you change them by appending or removing, that change will not be propagated to the copies of the dynamic array, even though they both share the same data
pointer (unless that also changes due to needing to resize memory). This is why dynamic arrays have to be passed by a pointer in most cases.
3 Likes