Skip to main content
8 events
when toggle format what by license comment
Nov 10, 2017 at 20:14 comment added Omnifarious @PhysicsCodingEnthusiast - And you never answered the question I asked on your main post, and that question is actually pretty important. It determines what your Network class (in particular) should look like, and it also determines just how important it is to not do dynamic allocation for the list of pointers to contacts stored in each particle.
Nov 10, 2017 at 20:12 comment added Omnifarious @PhysicsCodingEnthusiast - Two pointers to the same Contact. Leave it up to the Network to make sure that the pointers get deleted from the appropriate Particles before the Contact is deleted.
Nov 10, 2017 at 19:21 comment added AnInquiringMind Okay, so suppose that everything in my post is the same, except that I use regular pointers rather than shared pointers. Do my approaches to both questions make sense, or are there more efficient/performant approaches? Next, if I use regular pointers, should I have two pointers to the same Contact object, or should I try to use the same pointer for the vector of contacts for both particles (if that's even possible)? Thanks!
Nov 10, 2017 at 19:08 comment added Omnifarious No, shared_ptr should not be your goto whenever you have two pointers pointing to the same thing. It's about lifetime management. If you can't think of a sane way to manage the lifetime of an object than to have shared ownership semantics, use shared_ptr. Otherwise, don't. For example, I use a reference counted pointer in something where I have buffers that can be built out of fragments from other buffers. I don't copy any parts of the buffer, I refer to them from buffers that logically contain them. shared_ptr is the only way there.
Nov 10, 2017 at 19:07 comment added AnInquiringMind The number of contacts per particle should never exceed 6-7, but the number is not fixed (so a vector is preferable). I definitely care about performance, which I usually take to mean "right" in the context of C++!
Nov 10, 2017 at 19:02 comment added AnInquiringMind Thanks for the response! I can start responding here; if there is too much information, please let me know, and I can add the relevant portions to my question. The Network object should own all particles and contacts, and I will have a vector of Nc Contact objects called contacts (see my question). But if contacts[i] is between particles[j] and particles[k], and I want that information to be obtainable by network.getContacts(particles[j]) and network.getContacts(particles[k]), won't that require two pointers to the same object (which is the purpose of shared_ptr, right?)?
Nov 10, 2017 at 18:53 history edited Omnifarious CC BY-SA 3.0
added 12 characters in body
Nov 10, 2017 at 18:44 history answered Omnifarious CC BY-SA 3.0