Embedding pointers or values

I am going to use data structures below and pass them around in my application. They don’t have any methods attached to them at all. They won’t be modified where they are passed.

The question are (from the memory management point of view):

  1. should all the embedded structs be pointers or not?
  2. should I pass pointer of Person or copy?
  3. if I just create a pointer of Person but keep all the embedded structs as copy inside it, will it recreate copy of embedded structs again when Person variable is passed around or not?
  4. What would you personally do?

Thanks

type Person struct {
	Name           string
	ID             string
	OccupationUUID string
	Marital        bool
	Friends        Friend // pointer or not?
	NextOfKins     NextOfKin // pointer or not?
}

type Friend struct {
	Nation        string
	School        string
	HouseNumber   string
	HouseID       string
	BuildingCode  string
	Age           int
	Identity      string
	Opening       string
    Active        bool
    Mode          int
}

type NextOfKin struct {
	KinType KinType // pointer or not?
}

type KinType struct {
	KeyValue []KinTypeData // pointer or not?
}

type KinTypeData struct {
	Type string
	Name string
}

Beginning from the top i’d use poiters for the first three fields. For the KinTypeData slice i’d not use pointer if the data will be created for each person. If the data is referenced from another struct and will be updated synchronously you should use pointers as well.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.