what should be used New() or var in go? -


how object should created struct?

object := new(struct) 

or

var object struct 

i not understatnd when use what? , if both same 1 should prefered?

when need pointer object use new or composite literal else use var.

use var whenever possible more allocated in stack , memory freed scope ends. case of new memory gets allocated in heap , need garbage collected.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -