In some situations, there are differences. new(T) , as the name implies, returns a, well, a new instance of type T, while var b T is one instance, once and for all (err, actually until the end of its life cycle == goes out of scope , not available...).
Consider this cycle
var b bar for i := 0; i < 10; i++ { foo(&b) }
against
var b *bar for i := 0; i < 10; i++ { b = new(b) foo(b) }
In the later case, if foo , for example, stores its arg in some container, it leads to 10 instances of bar existing, while the first case has only one - in the variable b .
Another performance difference. The variable b will either be a fully static global variable, or it will usually be at a statically known offset in some function / method call record (a fancy name is usually a stack stack). new OTOH, if not optimized by the compiler, is a memory allocation call. Such a call will cost some non-zero time. If it is made in a loop and is not actually needed, then it can noticeably slow down some code path.
zzzz
source share