I'm not 100% sure, but… pretty sure? that the GC does not look at the len/cap fields of slices. Reason being that that would require significant alias-analysis, as two slices of the same underlying array can have different lengths and capacities. So treating the underlying array not as "one object" would require global knowledge about all slices of that array. I think you can assume that right now, the GC will treat the underlying array as one object and every slice as a pointer to that object (regardless of len/cap). That being said, I don't think it's advisable doing that. The GC may change and none of this is guaranteed by the language.
In regards to your second question: That would require having an array type for every possible size, which isn't really tenable. The memory usage of your program would explode even more, probably, than if you just use a slice. But you *can* use `make` to get a slice and then use `&s[0]` to get a pointer to its first element. i.e. something like this should work: https://play.golang.org/p/CWiyNzz3nYx AFAICT this conforms to the rules of unsafe pointers and thus works with the guarantees provided by the language. It does also mean, however, that you have to very carefully and tediously re-implement a bunch of language primitives using unsafe, so be sure that the performance gains are actually needed and worth it here. On Mon, Aug 20, 2018 at 2:13 PM 'Florian Uekermann' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Mistake in the second struct. The data field should have the type: > *[(^uint(0)) >> 17]uint64 > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.