Hi everyone, I how to best store potentially very large structures in a composite type. These structures won't be modified after initialization. My primary concern right now is performance instead of the possibility of accidentally overwriting the entries of these large structures. I'm experimenting with defining constants and immutable types. Here is a concrete example for my approach using immutable types:
immutable GPDataType data_X::Matrix; # could be huge data_y::Vector; # could be huge # ... and other things end type GPType data::GPData; choiceofalgorithm::Function; # ... and other things end I initialize by doing my_GP=GPType(GPDataType(X,y,...etc), onewaytoprocessGP, ... etc); I frequently call the function that is in the choiceofalgorithm field, which does a lot of this at the beginning to save the time it takes to derefence the structure pointers (a habit I have from C++): function onewaytoprocessGP(my_GP::GPType) data=my_GP.Data; # and other routines that uses Data in a read-only fashion. end My concern with this approach is that the documentation says immutable types are passed by value in function calls and assignments. If my understanding is correct, then there would be a lot of copies of the huge structure each time I do data=my_GP.Data; *** Here is a concrete example for my approach by defining a constant object to type GPDataType: type GPDataType data_X::Matrix; # could be huge data_y::Vector; # could be huge # ... and other things end type GPType data::GPData; choiceofalgorithm::Function; # ... and other things end I initialize by doing const tmp=GPDataType(X,y,...etc); my_GP=GPType(tmp, onewaytoprocessGP, ... etc); I use the same onewaytoprocessGP(my_GP::GPType) as before. My concern with this approach is that I'm unsure if this actually creates any performance savings over the non-constant object case. Any constructive advice is greatly appreciated :) Roy
