jxskiss/base62

Why the unsafe pointer reference?

Closed this issue · 2 comments

return *(*string)(unsafe.Pointer(&b))

Wouldn't this be the same as return string(bytes) and return []byte(str)?

This is a common unsafe trick, it avoids unnecessary memory allocation.

Hmm... I didn't realize that sort of casting would reallocate. I always assumed it was Copy-on-Write.