Exploring Internal Implementation of Go Slice

This blog is based on what I learned from reading the “Go Slices: Usage and Internals” blog post. When I read that blog post, I got curious and wanted to create my own version of a slice in a low-level language like C++. I wanted to understand how slices work in Go on a deeper level. I also wanted to confirm something mentioned in the Go Documentation they say that: slices are always passed by value, but they don’t copy all the data....

October 22, 2023 · 9 min · 1745 words · Jose Sitanggang

Boosting String and Bytes Conversions Speed by 140x with Zero Allocation in Go

Converting between a string and bytes requires allocating new memory. However, strings and bytes (which are essentially slices of bytes) share a similar memory structure. The main difference is that a slice can grow as needed, while a string remains immutable. We can gain insights into their internal structures by referring to the Go documentation. Strings are defined using StringHeader, while slices are defined using SliceHeader. To enhance clarity, we’ll include these definitions here:...

October 21, 2023 · 4 min · 706 words · Jose Sitanggang