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):
- should all the embedded structs be pointers or not?
- should I pass pointer of
Person
or copy? - 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 whenPerson
variable is passed around or not? - 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
}