Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How exactly are you planning on using this <code>std::vector</code>?</p> <p>You say iterating will take ages, but if your goal is to iterate over all values, you simply cannot do better than a contiguous array. You talk about deleting elements from the container, which suggests you need a dynamic array, which is exactly what <code>std::vector</code> is.</p> <p>Regardless, you definitely do not want to store a vector of raw pointers. Your two options should be <code>std::vector&lt;Particle&gt;</code> (generally preferred) or <code>std::vector&lt;unique_ptr&lt;Particle&gt;&gt;</code> (C++11 only) if you measure and find performance lacking due to using certain operations. Depending on your use case, <code>std::map&lt;Particle&gt;</code> or <code>std::set&lt;Particle&gt;</code> may be good ideas, but we don't have enough information.</p> <p>You are not storing any <code>Particle</code> on the stack. Every element in a <code>std::vector</code> is already in the free store ("the heap").</p> <p>Your insertion and deletion code should have nothing to do with your <code>Particle</code> class, either. Inserting and deleting is an operation on your container, not on the contained elements.</p> <p>To answer your question, we need to know a few things.</p> <p>First, how big is <code>Particle</code>? This is probably the most important information.</p> <p>Second, what are you doing with the container? Are you generally looking at every <code>Particle</code> and doing things with them, or are you searching for a particular <code>Particle</code> in your entire container? If you are searching, do you try and look up based on some kind of key (for instance, each <code>Particle</code> has a unique ID and you look up the whole <code>Particle</code> on that ID), or are you looking up to see if one <code>Particle</code> matches another (so in other words, you look up based on the identity of <code>Particle</code>)?</p> <p>If you are looking up an individual <code>Particle</code>, then <code>std::set</code> should probably be your first choice for ease of use, as it allows a binary search. If your use case has you search for particles by key, then you'll want <code>std::map&lt;Key, Particle&gt;</code>.</p> <p>If you have a bunch of Particles and you want to remove a few from the container, then the size of the object matters quite a bit. However, you'll generally want a <code>std::vector</code> for such a situation.</p> <p>In short, I'll need more information to fully answer your question.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload