[lug] Bash shell script question

Zan Lynx zlynx at acm.org
Wed Feb 21 19:20:30 MST 2018


On Wed, Feb 21, 2018 at 06:25:14PM -0700, BC wrote:
> Go's slices are wonderful, aren't they?

They are pretty great but like a few other Go constructs, they contain
hidden traps.

You have to always remember that the slice is actually a pointer. If you
pass a slice into a goroutine you either have to not use it from
anywhere else, or you have to use a sync.Mutex.

You also have to remember that appending to a slice returns a
potentially, but not always new copy of the backing array. I've seen
problems where some code kept writing to an old copy of the slice, but
that wasn't actually the array that was currently in use.

And there's potential garbage collection issues. It can surprise some
people that holding a byte slice of six characters can pin a 4K page.
This can happen a lot when parsing out of a file stream, then storing
that slice into a data structure without copying.

The same is true of maps. Maps all hold internal pointers and need to be
single-threaded or guarded by Mutex.

Still, Go has way fewer problems than C or C++. I do like it.


More information about the LUG mailing list