<?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[[Solved] Problem mit einer Liste beim freigeben&#x2F;clearen]]></title><description><![CDATA[<p>Hallo liebe Forengemeinde,</p>
<p>habe mich hier gerade mal angemeldet da ich mir öfters schon die Zähne manchen c/c++ Dingen ausgebissen haben, aber nun brauche ich endgültig Hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Zu meinem Problem, ich habe mir eine Stringliste ala TStrings von Delphi gebaut, Doppelt verkettete Liste alles ganz gewöhnlich eigentlich, nun ist diese aber beim Clearen etwas sehr langsam, und ich weiß keinen Rat mehr.</p>
<p>Hier noch etwas Code zum veranschaulichen des Ablauf:</p>
<pre><code class="language-cpp">struct SDataItem
{
    std::string strValue;
    __int64 intValue;
    void* dataValue;
};

struct SListItem
{
    int idx;
    SListItem* prev;
    SDataItem* data;
    SListItem* next;
};

/* ... */

void CStringList::Clear()
{
    SListItem* item = NULL;

    while (this-&gt;first != this-&gt;last)
    {
        item = this-&gt;first;

        if (item-&gt;next != NULL)
        {
            item-&gt;next-&gt;prev = item-&gt;prev;
        }
        if (item-&gt;prev != NULL)
        {
            item-&gt;prev-&gt;next = item-&gt;next;
        }

        if (this-&gt;first == item)
        {
            this-&gt;first = item-&gt;next;
        }
        if (this-&gt;last == item)
        {
            this-&gt;last = item-&gt;prev;
        }

        delete item-&gt;data; // &lt;- sobald ich das freigeben des data containers raus nehme ist das Clear in ~100ms duch sonst braucht er knapp 10 Sekunden
        delete item;
    }
}
</code></pre>
<p>Die Zeiten beziehen sich auf 100000 Einträge.<br />
Time (fill): 624ms<br />
Time (clear): 9735ms</p>
<p>Hoffe ihr könnt mir da weiterhelfen.</p>
<p>Viele Grüße<br />
Daniel</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/196319/solved-problem-mit-einer-liste-beim-freigeben-clearen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 10:07:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/196319.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 Oct 2007 11:50:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 19:18:31 GMT]]></title><description><![CDATA[<p>Hallo liebe Forengemeinde,</p>
<p>habe mich hier gerade mal angemeldet da ich mir öfters schon die Zähne manchen c/c++ Dingen ausgebissen haben, aber nun brauche ich endgültig Hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Zu meinem Problem, ich habe mir eine Stringliste ala TStrings von Delphi gebaut, Doppelt verkettete Liste alles ganz gewöhnlich eigentlich, nun ist diese aber beim Clearen etwas sehr langsam, und ich weiß keinen Rat mehr.</p>
<p>Hier noch etwas Code zum veranschaulichen des Ablauf:</p>
<pre><code class="language-cpp">struct SDataItem
{
    std::string strValue;
    __int64 intValue;
    void* dataValue;
};

struct SListItem
{
    int idx;
    SListItem* prev;
    SDataItem* data;
    SListItem* next;
};

/* ... */

void CStringList::Clear()
{
    SListItem* item = NULL;

    while (this-&gt;first != this-&gt;last)
    {
        item = this-&gt;first;

        if (item-&gt;next != NULL)
        {
            item-&gt;next-&gt;prev = item-&gt;prev;
        }
        if (item-&gt;prev != NULL)
        {
            item-&gt;prev-&gt;next = item-&gt;next;
        }

        if (this-&gt;first == item)
        {
            this-&gt;first = item-&gt;next;
        }
        if (this-&gt;last == item)
        {
            this-&gt;last = item-&gt;prev;
        }

        delete item-&gt;data; // &lt;- sobald ich das freigeben des data containers raus nehme ist das Clear in ~100ms duch sonst braucht er knapp 10 Sekunden
        delete item;
    }
}
</code></pre>
<p>Die Zeiten beziehen sich auf 100000 Einträge.<br />
Time (fill): 624ms<br />
Time (clear): 9735ms</p>
<p>Hoffe ihr könnt mir da weiterhelfen.</p>
<p>Viele Grüße<br />
Daniel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393520</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393520</guid><dc:creator><![CDATA[nali]]></dc:creator><pubDate>Sun, 28 Oct 2007 19:18:31 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 12:53:59 GMT]]></title><description><![CDATA[<p>versuchs mal prinzipiell einfacher:</p>
<pre><code class="language-cpp">next = this-&gt;start();
while (next != this-&gt;last) {
  item = next;
  next = item-&gt;next();
  delete item;
};
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393553</guid><dc:creator><![CDATA[crashterpiece]]></dc:creator><pubDate>Sun, 28 Oct 2007 12:53:59 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 13:10:55 GMT]]></title><description><![CDATA[<p>Die Schleife ist denke ich mal nicht das Problem, denn die läuft ohne ein delete in wenigen ms (10-20 bei 100000 Einträgen) durch. Das delete des data containers frisst wohl die Zeit, nur ich habe keine Ahnung warum, wenn ich &quot;delete item-&gt;data;&quot; auskommentiere ist die Laufzeit von Clear max. noch 90ms, aber wieso? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393564</guid><dc:creator><![CDATA[nali]]></dc:creator><pubDate>Sun, 28 Oct 2007 13:10:55 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 13:25:36 GMT]]></title><description><![CDATA[<p>mehr als eine halbe Sekunde für 100.000 Einträge (also mehr als 10.000 Zyklen pro Eintrag bei 1GHz - ein bisschen viel)? Ich hoffe doch, dass du deinen Compiler angewiesen hast, den Code zu optimieren. Andernfalls ist die Diskussion recht sinnlos.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393573</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sun, 28 Oct 2007 13:25:36 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 13:34:55 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>mehr als eine halbe Sekunde für 100.000 Einträge (also mehr als 10.000 Zyklen pro Eintrag bei 1GHz - ein bisschen viel)? Ich hoffe doch, dass du deinen Compiler angewiesen hast, den Code zu optimieren. Andernfalls ist die Diskussion recht sinnlos.</p>
</blockquote>
<p>In meinen Augen etwas ZU viel...</p>
<p>Im Debug und Release (auf volle Optimierung eingestellt VS2005 Standard) Build beides in etwa das selbe +-100ms vllt. Hatte anfangs auch gedacht es liegt am Debug Build, aber wie gesagt mit Release Config das selbe!</p>
<p>Ich habe auch schon VS gesagt es solle den ICL anstelle des MS-Compiler nehmen, selbe in Grün <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":-/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393575</guid><dc:creator><![CDATA[nali]]></dc:creator><pubDate>Sun, 28 Oct 2007 13:34:55 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 13:36:53 GMT]]></title><description><![CDATA[<p>Würdest du mal compilerfähigen Code zeigen, der dieses Verhalten hat?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393576</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393576</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sun, 28 Oct 2007 13:36:53 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 13:57:43 GMT]]></title><description><![CDATA[<p>Klar, ich habe mal das notwendigste zusammengepackt, es verhält sich genauso wie im eigentlichen Projekt.</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;string&gt;

struct SDataItem
{
    std::string strValue;
    __int64 intValue;
    void* dataValue;
};

struct SListItem
{
    int idx;
    SListItem* prev;
    SDataItem* data;
    SListItem* next;
};

class CStringList
{
    private:
        int count;
        SListItem* first;
        SListItem* last;
    public:
        CStringList(void)
        {
            this-&gt;count = 0;
            this-&gt;first = NULL;
            this-&gt;last  = NULL;
        };

        ~CStringList(void)
        {
            this-&gt;Clear();
        }

        int AddItem(const char* str, __int64 number, void* data)
        {
            this-&gt;count++;

            SListItem* item     = new SListItem;
            SDataItem* itemdata = new SDataItem;

            itemdata-&gt;dataValue = data;
            itemdata-&gt;intValue  = number;
            itemdata-&gt;strValue  = str;

            item-&gt;idx  = 0;
            item-&gt;data = itemdata;
            item-&gt;prev = NULL;
            item-&gt;next = NULL;

            if ((this-&gt;first != NULL) &amp;&amp; (this-&gt;last != NULL))
            {
                this-&gt;last-&gt;next = item;
                item-&gt;idx        = this-&gt;last-&gt;idx + 1;
                item-&gt;prev       = this-&gt;last;
                item-&gt;next       = NULL;
            } else
            {
                this-&gt;first = item;
            }

            this-&gt;last = item;

            return item-&gt;idx;
        };

        void Clear()
        {
            SListItem* item = NULL;

            while (this-&gt;first != this-&gt;last)
            {
                item = this-&gt;first;

                if (item-&gt;next != NULL)
                {
                    item-&gt;next-&gt;prev = item-&gt;prev;
                }
                if (item-&gt;prev != NULL)
                {
                    item-&gt;prev-&gt;next = item-&gt;next;
                }

                if (this-&gt;first == item)
                {
                    this-&gt;first = item-&gt;next;
                }
	            if (this-&gt;last == item)
                {
                    this-&gt;last = item-&gt;prev;
                }

                delete item-&gt;data;
                delete item;
            }

            this-&gt;count = 0;
        };
};

int main(int argc, const char* argv[])
{
    char text[128];
    CStringList *strLst = new CStringList();

    DWORD tick = GetTickCount();
    for (int i = 0; i &lt; 100000; i++)
    {
        sprintf(text,&quot;Foooooooooooo%d\0&quot;,i);
        strLst-&gt;AddItem(text,i,NULL);
    }
    printf(&quot;Time (fill): %d\r\n&quot;,GetTickCount() - tick);

    tick = GetTickCount();
    strLst-&gt;Clear();
    printf(&quot;Time (delete): %d\r\n&quot;,GetTickCount() - tick);

    delete strLst;

    getch();

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1393585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393585</guid><dc:creator><![CDATA[nali]]></dc:creator><pubDate>Sun, 28 Oct 2007 13:57:43 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 16:54:49 GMT]]></title><description><![CDATA[<p>kann ich nicht nachvollziehen. wie sehen denn die Optimierungseinstellungen aus und welchen Prozessor verwendest du?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393688</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sun, 28 Oct 2007 16:54:49 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 17:41:32 GMT]]></title><description><![CDATA[<p>Urgs, sitze gerade am Notebook, dachte schau mal ins Forum ob sich schon jemand gemeldet hat, und als ich dein Beitrag las dachter ich mir so, hmm teste es mal hier (mit dem Debug Build getestet):</p>
<p>Time (fill): 1141<br />
Time (delete): 531</p>
<p>Es ist die selbe Executable.</p>
<p>Meine Workstation ist ein Intel D950 (2 Cores) 3,4Ghz (OS:Vista x32) das Notebool ist ein Centrino (1 Core) 1,3Ghz (OS:XP).</p>
<p>Dann ist jetzt meine Frage warum ist es auf meiner Workstation so langsam?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393710</guid><dc:creator><![CDATA[nali]]></dc:creator><pubDate>Sun, 28 Oct 2007 17:41:32 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Problem mit einer Liste beim freigeben&#x2F;clearen on Sun, 28 Oct 2007 19:17:30 GMT]]></title><description><![CDATA[<p>Ok das Problem hat sich gelößt, sowas beklopptes echt mal, der Debugger war schuld. Ich habe die Anwenudng auf dem Notebook ja nicht in der IDE mit laufendem Debugger gestartet, aber der wurstet da wohl so extrem im Speicher rum das das so lange dauert. Darauf muss man erst mal kommen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
<p>Naja man lernt nie aus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> Dennoch vielen Dank für die Mühen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1393784</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1393784</guid><dc:creator><![CDATA[nali]]></dc:creator><pubDate>Sun, 28 Oct 2007 19:17:30 GMT</pubDate></item></channel></rss>