No, exp = dataPool.instrument.profile.experiment does not make a deep data copy, but the fields of exp are shared data copies. Then this adds two new fields:
exp.fieldA = 1:100;
exp.fieldB.fieldB1 = rand(100);
Then the temporary exp is copied back again:
dataPool.instrument.profile.experiment = exp;
This creates again shared data copied, such that the memory for the data is not duplicated. In some usual test scenarios this is faster than:
dataPool.instrument.profile.experiment.fieldA = 1:100;
dataPool.instrument.profile.experiment.fieldB.fieldB1 = rand(100);
The overhead for addressing the substructs causes the delay. But the timings can and will depend on the Matlab version and most likely the number of fields and the depth of the nested structure. Because the field addressing does not require a lot of time, the differences in the timings are small and the example "rand(100)" will be more expensive. But when exp contains large data already, the shared data copy method help to reduce the processing time.
0 Comments
Sign in to comment.