Performance of function slice parameter vs global variable?

Judging from the name of your function, performance can’t be that critical to even consider moving parameters to global variables just to save time/space required to pass them as parameters (IO operations like checking files are much-much slower than calling functions and passing values to them). Slices in Go are just small descriptors, something like … Read more

What is copy-on-write?

I was going to write up my own explanation but this Wikipedia article pretty much sums it up. Here is the basic concept: Copy-on-write (sometimes referred to as “COW”) is an optimization strategy used in computer programming. The fundamental idea is that if multiple callers ask for resources which are initially indistinguishable, you can give … Read more

Legality of COW std::string implementation in C++11

It’s not allowed, because as per the standard 21.4.1 p6, invalidation of iterators/references is only allowed for — as an argument to any standard library function taking a reference to non-const basic_string as an argument. — Calling non-const member functions, except operator[], at, front, back, begin, rbegin, end, and rend. For a COW string, calling … Read more