On Thu, Apr 20, 2017 at 9:42 AM Will Faught <will.fau...@gmail.com> wrote:

> Why couldn't maps be implemented as a pointer to the map implementation?
If you try to use the map and the pointer is nil, then the map allocates
the backing implementation. Pseudocode for a built-in implementation:
>
> type map struct {
> impl *mapimpl
> }
>
>
> func (m map) set(k, v interface{}) { // used for m[k] = v
> if m.impl == nil {
> m.impl = newMapImpl()
> }
> m.impl.set(k, v)
> }

Without a pointer receiver the set method above is ineffective. With a
pointer receiver every map operation is double dereferencing.

-- 

-j

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to