alphadose / haxmap

Fastest and most memory efficient golang concurrent hashmap
MIT License
892 stars 45 forks source link

[Question]: why are there empty structs in atomic? #46

Closed mvestnik closed 3 months ago

mvestnik commented 3 months ago

In atomic.go:

type noCopy struct{}

func (c *noCopy) Lock()   {}
func (c *noCopy) Unlock() {}

type atomicUint32 struct {
  _ noCopy
  v uint32
}

is this filler (_ noCopy) for semantics or does it actually prevent copying?

semihbkgr commented 3 months ago

noCopy implements sync.Locker so that go vet can trigger warnings when types embedding noCopy are copied.

It is primarily used to trigger go vet warnings in cases where types with the '_noCopy' field are being copied.

You can find similar use cases in the Go std package: https://github.com/golang/go/blob/48b10c9af7955bcab179b60a148a633a0a75cde7/src/sync/atomic/type.go#L191

mvestnik commented 3 months ago

Thank you very much, I got it.