You might be interested in this package:
https://pkg.go.dev/go4.org/intern
It is probably your best choice for a long-term maintained implementation
of this concept. Matt Layher explained the rationale and design here:
https://mdlayher.com/blog/unsafe-string-interning-in-go/
and Brad Fitzpatrick wrote a blog post about how Tailscale uses it here:
https://tailscale.com/blog/netaddr-new-ip-type-for-go/

On Mon, Jan 10, 2022 at 12:30 AM jlfo...@berkeley.edu <
jlforr...@berkeley.edu> wrote:

>
>
> On Sunday, January 9, 2022 at 3:07:18 PM UTC-8 bse...@computer.org wrote:
>
>> Note that a with a map[string]string, the code:
>>
>> m[s]=s
>>
>> The contents of the string s are not duplicated, only the string header s
>> is.
>>
>
> I didn't know this. That's very good to know.
>
> What about this:
>
> package main
>
> type word struct {
>   s string
>   refcnt int
> }
>
> var w1 = word {"moby", 1}
>
> func main() {
>         m := make(map[string]word)
>         m["moby"] = w1
> }
>
> This is a little closer to what I'd like to do.
> How many times would the string "moby" be stored?
>
> Thanks,
> Jon
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/6f06bbe8-8d50-46f6-8b28-f4e680ecae43n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/6f06bbe8-8d50-46f6-8b28-f4e680ecae43n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfGDQ2e3djAZqqDpaR%3DpuGQext9oYNViazdkT3W53r4D1g%40mail.gmail.com.

Reply via email to