Skip to main content
9 events
when toggle format what by license comment
Nov 19, 2017 at 22:50 comment added Frank Hileman Yes. The other option is a listener type object that invalidates itself whenever the collection changes. That separates computation from the collection,
Nov 18, 2017 at 15:22 comment added AnInquiringMind @FrankHileman Okay, so in terms of concrete implementation in this case, you would recommend having a private std::vector<std::valarray<double>> separationVectors that can only be accessed through member functions of the Configuration class. Then, whenever the particles' positions have changed, a member variable of type bool called, say, isModified can be set to true, so that the next time the separation vectors are needed, they will be recomputed. Is that what you had in mind? It's sometimes hard to translate abstract explanations to concrete implementations. Thank you!
Nov 18, 2017 at 0:48 comment added Frank Hileman "Encapsulation" in my specific comment was referring to prohibiting users of the container from modifying the mutable collection directly; instead, they must use member methods, and each time a mutation occurs, an invalid flag is set on that container. Then when you retrieve the computation result, it is only recomputed if the invalid flag is set, otherwise the cached result is returned (this is basic design for cached results). The other option is to get the same result by invalidating a secondary object which is immutably bound, but accessible as a separate instance in the public API.
Nov 17, 2017 at 21:48 comment added AnInquiringMind @FrankHileman Could you expand a bit more on what you mean by "Encapsulation, or an invariant between classes, would ensure the cached results are always synchronized with the mutable collection, when you retrieve them."? I'm not entirely sure what encapsulation means in this context. Thanks!
Nov 17, 2017 at 21:46 vote accept AnInquiringMind
Nov 17, 2017 at 17:27 comment added Frank Hileman Encapsulation, or an invariant between classes, would ensure the cached results are always synchronized with the mutable collection, when you retrieve them. This can be done with a dirty flag or by recomputing every time the collection is mutated.
Nov 17, 2017 at 8:08 comment added Bart van Ingen Schenau @PhysicsCodingEnthusiast: Yes, that is right.
Nov 17, 2017 at 4:16 comment added AnInquiringMind Thanks for the response. "Typically the cached result is stored in the same object containing the inputs, which is the same object performing the computation." Just to be sure, object here refers to a class object, right? In that case, the object would be an instance of the Configuration class (it contains the inputs and the member functions performing the computations), and so the cached result could be "stored in the same object" via a member data container such as the separationVectors vector I suggested in my question, right?
Nov 17, 2017 at 1:39 history answered Frank Hileman CC BY-SA 3.0