struct StructA
{
int i;
int j;
};
// Method 1
struct StructBA
{
int k;
StructA sa;
}
// Method 2
struct StructCA
{
int m;
StructA *psa;
};
// Method 3
struct StructDA
{
int n;
boost::shared_ptr<StructA> psa;
};
Basically, I need to pass a structure which contains other structures as a function parameter to constructor of a class. what is the best design practice in this situation?
Note: please correct my understanding if it is incorrect.
My understanding for method 1> There is the simplest way to handle the data and we don't need to explicitly allocate resource and release resource. The only concern is that it may involve unnecessary copies. However, if I always use pass by reference, this should not be a problem.
My understanding for method 2> This method has been used extensively in FMOD library (http://www.fmod.org/), so it must have its edge. But we have to manually allocate and release resource.
My understanding for method 3> It removes the requirement for manually releasing the allocated resource but it involves overhead compared to method 2.
So which method should I use in practice and when?