Golang collection resizing problem?

HI all,

Please recommend me some good tutorial (hoepfully regarding hte more recent versions of Golang) about the collection resizing problem.

Also, if there are any tips or tricks you can point out, I am really curious to find out more on this.

1 Like

What exactly is this problem?

2 Likes

Hi, @JOhn_Stuart, can you clarify what you mean by “the collection resizing problem?” I’ve been Googling around a few different permutations of that phrase but haven’t found anything that seems relevant.

2 Likes

Hi @lutzhorn and @skillian,

Thank you for your quick replies. Here is what I mean by the collection resizing problem: when you append elements to a slice, or add to a map, it will internally allocate more memory (when apended/added enough elements).

I would like to know more about the internal implementation of slice and map. Also maybe strings.builder or other Go data structures that allocate memory internally (by themselves, transparent to the user) could have an interesting behaviour when adding more elements (runes) to them.

I now realize that I have misused the word problem: indeed this is just normal behaviour I would like to know more about. Also, maybe some tips to minimize wasted memory (automatically allocated but never used) would be of great help to me.

Where can I find more information about this ?

1 Like

The Go source code is available on GitHub.

A read-only version of the code is also reachable from the docs, for example strings/builder.go.

Just today I found the following article which may be of interest.

https://philpearl.github.io/post/bad_go_not_sizing_arrays

3 Likes

Thanks for pointing out the Go source code :sweat_smile:

@JOhn_Stuart a good way to start is the Go Slices Article, see https://blog.golang.org/go-slices-usage-and-internals
Also have a look at the ‘Further Reading’ at the end of the article.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.