-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use std::unique_ptr
s for storing model definitions
#153
Conversation
These operations will always succeed, so there's no need to signal anything in the return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
James explained to me the difference between shared_ptr
and unique_ptr
and while I did not grasped everything, I gathered that using the second option was not possible in this case since we need to have multiple copies of it in different places. Needless to say that I'm not an expert in C++, so maybe I got this totally wrong....
Yeah, I made this suggestion on @jamesturner246's PR and we did come to the conclusion that it probably needed to be a
|
There's a chance that they want to be able to modify model parameters -- i.e. contents of model definition -- mid simulation. I'm not yet decided on where it might be modified from, but would this be a faff to change to non-const in future, should we need to modify from tbh I don't like these 'definition' classes anyway, and getting rid of them would mean we would only modify the model object directly. |
That sounds v bizarre 😆 but I'm sure there's a good reason for it! Yes, you could easily modify it to be non- I did wonder if we might be able to remove the model definition classes, but having had a look just now, I'm wondering how we'd be able to construct models without having the params encapsulated in a separate class somewhere? (That's assuming that we actually do want to cache model parameters rather than reloading them every time.) |
The only sensible reason I could think of for caching parameters was if they wanted some persistent interface in future, where they could stop, reinitialise, restart, etcetera, which would mean re-initialising from some pristine confifg. In which case, you're right, it's probably better to keep the 'definition' classes, keep the cache constant, and just copy out of it whenever they need fresh state. If they don't want that, then there's no reason to cache anything. But I suppose they might want that in future, so I guess that's reason enough to keep the pristine cache. I imagine a |
Rather than wondering what they might want, why do you ask them (after giving some context of the issue)? |
I'll bring it up with them this week. |
I fancied tinkering with some code rather than just config files, so I did this, even though it's not in the backlog and is a pretty minor refactor 😛.
Currently, the model definitions are stored in the repository (of type
CachedRepository
) asstd::shared_ptr
s, even though they don't really need to be "shared", because the repository object will outlive any of the users of these model definitions. So instead, I've changed these to bestd::unique_ptr
s; when they're needed they can be accessed as good old-fashioned const refs.I also changed a couple of small issues I spotted on the way.