4 ms·
Go supports this, I think. I am not quite sure what is meant by object relative layout. In Go: A struct is laid out as you declared it, with possible compiler
by fmstephe 11y ago
Go supports this, I think. I am not quite sure what is meant by object relative layout.
In Go:
A struct is laid out as you declared it, with possible compiler added padding.
A struct value field (not a pointer) in another struct is laid out contiguously in memory as you declared it.
An array (or a slice) of values (no pointers) are laid out contiguously in memory.
You can happily take pointers into any of these larger structures. If you had a data structure where you really wanted to control the layout, you can create a slab allocator as a big array of values, and take pointers into that array to allocate pieces of your data structure. I did this exact thing to write a red-black tree in Go.
It is true that Go's GC isn't compacting. But it will be in the future (or it is planned to be).
But, if I hadn't programmed in Go I would have agreed with your comment above.