Note that there are some explanatory texts on larger screens.

plurals
  1. POEfficiency of std::tuple and std::map
    primarykey
    data
    text
    <p>I am currently building a program that relies on multiple vectors and maps to retain previously computed information. My vectors are of the standard format, and not very interesting. The maps are of the form</p> <pre><code>std::map&lt;std::string, long double&gt; </code></pre> <p>with the intent of the string being a parseable mapping of one vector onto another, such as</p> <pre><code>std::map&lt;std::string, long double&gt; rmMap("fvProperty --&gt; fvTime", 3.0234); </code></pre> <p>where I can later on split the string and compare the substrings to the vector names to figure out which ones were involved in getting the number. However, I have recently found that std::tuple is available, meaning I can skip the string entirely and use the vector positions instead with</p> <pre><code>std::tuple&lt;unsigned int, unsigned int, long double&gt; </code></pre> <p>This allows me (as far as I can tell) to use both the first and the second value as a key, which seems preferable to parsing a string for my indices. </p> <p>My crux is that I am unaware of the efficiency here. There will be <em>a lot</em> of calls to these tuples/maps, and efficacy is of the essence, as the program is expected to run for weeks before producing an end result.</p> <p>Thus, I would ask you if tuples are more or equally efficient (in terms of memory, cache, and cycles) than maps when it comes to large and computationally intense programs.</p> <p>EDIT: If tuples cannot be used in this way, would the map</p> <pre><code>std::map&lt;std::pair&lt;unsigned int, unsigned int&gt;, long double&gt; </code></pre> <p>be an effective substitute to using strings for identification?</p>
    singulars
    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.
 

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