<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Doppelter Speicherverbrauch beim Kopieren]]></title><description><![CDATA[<p>In folgendem Code habe ich für kurze Zeit wegen des Kopiervorgangs den doppelten Speicherverbrauch:</p>
<pre><code class="language-cpp">// Speicherbedarf OK.
boost::unordered_map&lt;std::string, Info&gt; indexed_by_a;
// Weiterer Code zum &quot;befüllen&quot; von &lt;indexed_by_a&gt;.
boost::unordered_map&lt;std::string, Info&gt; indexed_by_b;
// Ab hier wächst der Speicherbedarf bis auf das Doppelte.
for (boost::unordered_map&lt;std::string, Info&gt;::const_iterator cit(
  indexed_by_a.begin()), cit_end(indexed_by_a.end());
  cit != cit_end; ++cit) {
  indexed_by_b.insert(
    std::pair&lt;std::string, Info&gt;(cit-&gt;second.b, cit-&gt;second));
}
indexed_by_a.clear();
// Kopieren beendet, Speicherbedarf wieder OK.
</code></pre>
<p>Gibt es eine Möglichkeit während des Kopierens den Speicherverbrauch zu reduzieren? Soweit ist weiss, ist es nicht möglich die Kopierbasis &lt;indexed_by_a&gt; beim Verwenden von Interatoren (also in der Schleife) zu manipulieren.</p>
<p>Vielen Dank für Eure Ideen!<br />
T.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/300732/doppelter-speicherverbrauch-beim-kopieren</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 15:17:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/300732.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Mar 2012 09:50:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Doppelter Speicherverbrauch beim Kopieren on Fri, 09 Mar 2012 09:52:17 GMT]]></title><description><![CDATA[<p>In folgendem Code habe ich für kurze Zeit wegen des Kopiervorgangs den doppelten Speicherverbrauch:</p>
<pre><code class="language-cpp">// Speicherbedarf OK.
boost::unordered_map&lt;std::string, Info&gt; indexed_by_a;
// Weiterer Code zum &quot;befüllen&quot; von &lt;indexed_by_a&gt;.
boost::unordered_map&lt;std::string, Info&gt; indexed_by_b;
// Ab hier wächst der Speicherbedarf bis auf das Doppelte.
for (boost::unordered_map&lt;std::string, Info&gt;::const_iterator cit(
  indexed_by_a.begin()), cit_end(indexed_by_a.end());
  cit != cit_end; ++cit) {
  indexed_by_b.insert(
    std::pair&lt;std::string, Info&gt;(cit-&gt;second.b, cit-&gt;second));
}
indexed_by_a.clear();
// Kopieren beendet, Speicherbedarf wieder OK.
</code></pre>
<p>Gibt es eine Möglichkeit während des Kopierens den Speicherverbrauch zu reduzieren? Soweit ist weiss, ist es nicht möglich die Kopierbasis &lt;indexed_by_a&gt; beim Verwenden von Interatoren (also in der Schleife) zu manipulieren.</p>
<p>Vielen Dank für Eure Ideen!<br />
T.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190040</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190040</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Fri, 09 Mar 2012 09:52:17 GMT</pubDate></item><item><title><![CDATA[Reply to Doppelter Speicherverbrauch beim Kopieren on Fri, 09 Mar 2012 11:51:53 GMT]]></title><description><![CDATA[<p>Vielleicht solltest Du Dir mal<a href="http://www.boost.org/doc/libs/1_49_0/libs/multi_index/doc/index.html" rel="nofollow"> <code>boost.multi_index</code> </a>angucken. Mir sieht es stark danach aus, als wenn Du genau das haben willst:</p>
<pre><code class="language-cpp">#include &lt;boost/multi_index_container.hpp&gt;
#include &lt;boost/multi_index/ordered_index.hpp&gt;
#include &lt;boost/multi_index/identity.hpp&gt;
#include &lt;boost/multi_index/mem_fun.hpp&gt;

#include &lt;string&gt;
#include &lt;iostream&gt;

class info
{
public:
    info(std::string const &amp; a, std::string const &amp; b): m_a(a), m_b(b){}
    std::string const &amp; a() const{ return m_a; }
    std::string const &amp; b() const{ return m_b; }
private:
    std::string m_a;
    std::string m_b;
};

std::ostream &amp; operator&lt;&lt;(std::ostream &amp; ostr, info const &amp; i)
{
    return (ostr &lt;&lt; i.a() &lt;&lt; ' ' &lt;&lt; i.b());
}

struct by_index_a{};
struct by_index_b{};

namespace bmi = boost::multi_index;

typedef bmi::multi_index_container
    &lt; info
    , bmi::indexed_by
        &lt; bmi::ordered_unique&lt;bmi::tag&lt;by_index_a&gt;, bmi::const_mem_fun&lt;info, std::string const &amp;, &amp;info::a&gt; &gt;
        , bmi::ordered_unique&lt;bmi::tag&lt;by_index_b&gt;, bmi::const_mem_fun&lt;info, std::string const &amp;, &amp;info::b&gt; &gt;
        &gt;
    &gt;
info_storage;

int main()
{
    info_storage infos;
    infos.insert(info(&quot;hallo&quot;, &quot;welt&quot;));
    infos.insert(info(&quot;ciao&quot;, &quot;mond&quot;));

    std::cout &lt;&lt; *infos.get&lt;by_index_a&gt;().find(&quot;ciao&quot;) &lt;&lt; std::endl; //suche nach index a
    std::cout &lt;&lt; *infos.get&lt;by_index_b&gt;().find(&quot;mond&quot;) &lt;&lt; std::endl; //suche nach index b
}
</code></pre>
<p>Das würde das Kopieren komplett überflüssig machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2190055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2190055</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 09 Mar 2012 11:51:53 GMT</pubDate></item><item><title><![CDATA[Reply to Doppelter Speicherverbrauch beim Kopieren on Tue, 13 Mar 2012 09:36:25 GMT]]></title><description><![CDATA[<p>Danke für den Hinweis!</p>
<p>Hier meine Testimplementierung. Bin noch am Herausfinden, wie ich mit der Funktion &quot;modify()&quot; arbeiten kann.</p>
<p><a href="http://www.highscore.de/cpp/boost/container.html#container_multiindex" rel="nofollow">http://www.highscore.de/cpp/boost/container.html#container_multiindex</a></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;  // NOLINT
#include &lt;string&gt;

#include &lt;boost/multi_index_container.hpp&gt;
#include &lt;boost/multi_index/member.hpp&gt;
#include &lt;boost/multi_index/hashed_index.hpp&gt;
#include &lt;boost/multi_index/composite_key.hpp&gt;

struct entry {
  std::string path;
  std::string a;
  std::string b;
  std::string c;

  entry(const std::string&amp; path, const std::string&amp; a,
    const std::string&amp; b, const std::string&amp; c) : path(path), a(a),
    b(b), c(c) {
  }

  friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const entry&amp; e) {
    os &lt;&lt; e.path &lt;&lt; &quot;\n&quot; &lt;&lt; e.a &lt;&lt; &quot;\n&quot; &lt;&lt; e.b &lt;&lt; &quot;\n&quot; &lt;&lt; e.c &lt;&lt; &quot;\n&quot;;
    return os;
  }
};

typedef boost::multi_index::multi_index_container&lt;
  entry,
  boost::multi_index::indexed_by&lt;
    boost::multi_index::hashed_non_unique&lt;
      boost::multi_index::member&lt;entry, std::string, &amp;entry::path&gt;
    &gt;,
    boost::multi_index::hashed_non_unique&lt;
      boost::multi_index::composite_key&lt;
        entry,
        boost::multi_index::member&lt;entry, std::string, &amp;entry::a&gt;,
        boost::multi_index::member&lt;entry, std::string, &amp;entry::b&gt;,
        boost::multi_index::member&lt;entry, std::string, &amp;entry::c&gt;
      &gt;
    &gt;
  &gt;
&gt; entry_bimap;

int main() {
  entry_bimap eb;

  eb.insert(entry(&quot;a.exe&quot;, &quot;11&quot;, &quot;22&quot;, &quot;33&quot;));
  eb.insert(entry(&quot;b.exe&quot;, &quot;44&quot;, &quot;55&quot;, &quot;66&quot;));
  eb.insert(entry(&quot;c.exe&quot;, &quot;77&quot;, &quot;88&quot;, &quot;99&quot;));

  std::cout &lt;&lt; *eb.find(&quot;b.exe&quot;) &lt;&lt; &quot;\n&quot;;
  std::cout &lt;&lt; *eb.get&lt;1&gt;().find(boost::make_tuple(&quot;77&quot;, &quot;88&quot;, &quot;99&quot;)) &lt;&lt; &quot;\n&quot;;
  const crc_bimap::nth_index&lt;1&gt;::type&amp; x = eb.get&lt;1&gt;();
  std::cout &lt;&lt; *x.find(boost::make_tuple(&quot;44&quot;, &quot;55&quot;, &quot;66&quot;)) &lt;&lt; &quot;\n&quot;;

  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2191114</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2191114</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Tue, 13 Mar 2012 09:36:25 GMT</pubDate></item></channel></rss>