type Point struct {
x, y int
}
var arr [4]Point
How will the array be laid out in memory?
Will the actual objects be laid out side by side
[Point[x][y]][Point[x][y]][Point[x][y]][Point[x][y]]
Or will the array be a array of pointers, with the objects stored elsewhere, like Java?
[&Point0][&Point1][&Point2][&Point3]
Somewhere in the heap:
...[Point0[x][y]] ... [Point1[x][y]] .... [Point3[x][y]] ... [Point2[x][y]]
Also, how will make()
lay out slices in memory?
make([]Point, 10)
The 4 Point
s will be contiguous in memory, as in your first example. If you want them to be pointers, then you'd need [4]*Point
.
A slice of Point
creates a slice that uses (points to) a backing array, where, again, Point
s would be side-by-side (and []*Point
would be a slice of pointers to Point
).
See http://research.swtch.com/godata for a good explanation of memory layouts of Go data structures.