<?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[allocator und list-implementierung]]></title><description><![CDATA[<p>Wenn ich eine std::list&lt;T,std::allocator&lt;T&gt;&gt; erstelle kann ich auch den allocator angeben. dieser ist wie man sehen kann für den typ 'T'.<br />
Für die implementierung der liste müssen jedoch objecte vom folgenden typ erstellt werden:</p>
<pre><code>struct node{
node* next;
node* next;
T val;
};
</code></pre>
<pre><code>typename std::allocator&lt;node&gt; Alloc
</code></pre>
<p>Meine frage ist nun wie um himmels willen der typ des allocators geändert wird <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Ich hab jetzt über ne stunde im code rumgesucht (visual studio) und hab es nicht verstanden.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/317980/allocator-und-list-implementierung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Jul 2026 22:52:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/317980.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Jun 2013 18:18:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:19:34 GMT]]></title><description><![CDATA[<p>Wenn ich eine std::list&lt;T,std::allocator&lt;T&gt;&gt; erstelle kann ich auch den allocator angeben. dieser ist wie man sehen kann für den typ 'T'.<br />
Für die implementierung der liste müssen jedoch objecte vom folgenden typ erstellt werden:</p>
<pre><code>struct node{
node* next;
node* next;
T val;
};
</code></pre>
<pre><code>typename std::allocator&lt;node&gt; Alloc
</code></pre>
<p>Meine frage ist nun wie um himmels willen der typ des allocators geändert wird <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Ich hab jetzt über ne stunde im code rumgesucht (visual studio) und hab es nicht verstanden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334616</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334616</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:19:34 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:21:11 GMT]]></title><description><![CDATA[<p>per <a href="http://msdn.microsoft.com/en-us/library/5fk3e8ek(v=vs.80).aspx" rel="nofollow">rebind</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334618</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:21:11 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:27:22 GMT]]></title><description><![CDATA[<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>per <a href="http://msdn.microsoft.com/en-us/library/5fk3e8ek(v=vs.80).aspx" rel="nofollow">rebind</a>.</p>
</blockquote>
<p>danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /></p>
<p>geht das nur mit allocatoren? da würden mir direkt eine menge anderer anwendungszwecke für eine solche funktion einfallen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334622</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:27:22 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:30:04 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>geht das nur mit allocatoren? da würden mir direkt eine menge anderer anwendungszwecke für eine solche funktion einfallen...</p>
</blockquote>
<p>Beispiel?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334624</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:30:04 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:32:25 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>Shade Of Mine schrieb:</p>
<blockquote>
<p>per <a href="http://msdn.microsoft.com/en-us/library/5fk3e8ek(v=vs.80).aspx" rel="nofollow">rebind</a>.</p>
</blockquote>
<p>danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /></p>
<p>geht das nur mit allocatoren? da würden mir direkt eine menge anderer anwendungszwecke für eine solche funktion einfallen...</p>
</blockquote>
<p>Die Technik funktioniert ueberall - aber die Klasse muss dieses Interface halt anbieten. Allocatoren haben halt rebind als Member - einen vector&lt;int&gt; auf vector&lt;double&gt; kann man so leider nicht umbiegen - dazu muss das rebind leider immer auf den Typen spezialisiert sein.</p>
<p>Das Problem ist naemlich, dass ein vector&lt;int&gt; in wirklichkeit ja ein vector&lt;int, allocator&lt;int&gt; &gt; ist, oder noch schlimmer vielleicht sogar ein vector&lt;int, allocator&lt;int&gt;, foo, bar, baz&gt; - um hier nun int in float zu tauschen, muss man natuerlich alle Parameter kennen. Deshalb gibt es kein generisches Rebind fuer alle Typen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334625</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:32:25 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:36:06 GMT]]></title><description><![CDATA[<p>super antwort, danke <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/2334628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334628</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:36:06 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:42:50 GMT]]></title><description><![CDATA[<p>oh, eine letzte frage noch, wie wird dann ein allocator vom typ std::allocator&lt;T&gt;<br />
intern zurückgegeben, wenn doch eigentlich intern nur ein std::allocator&lt;node&gt; existiert?<br />
Man kann doch wohl keine objecte mit rebind verändern, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334630</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334630</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:42:50 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:49:31 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>oh, eine letzte frage noch, wie wird dann ein allocator vom typ std::allocator&lt;T&gt;<br />
intern zurückgegeben, wenn doch eigentlich intern nur ein std::allocator&lt;node&gt; existiert?<br />
Man kann doch wohl keine objecte mit rebind verändern, oder?</p>
</blockquote>
<p>Nein. Deswegen ist ein zweites, unbenutztes Objekt vom Ursprünglichen Allokator-Typ zu halten und als Kopie zurückzugeben.</p>
<p>Diese Diskussion wurde schon in Swordfishs Thread geführt. <a href="http://www.c-plusplus.net/forum/317842-30" rel="nofollow">http://www.c-plusplus.net/forum/317842-30</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334632</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334632</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:49:31 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 18:51:34 GMT]]></title><description><![CDATA[<p>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334633</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Wed, 26 Jun 2013 18:51:34 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 19:01:06 GMT]]></title><description><![CDATA[<p>ich habs jetzt einfach so gelöst, dass ich intern einen std::allocator&lt;int&gt; habe, den aber nur über Al::rebind&lt;Node&gt;::other(this-&gt;Myal) aufrufe <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="😉"
    /> so kann ich den gewünschten typ zurückgeben und trotzdem Node-objecte erstellen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334635</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Wed, 26 Jun 2013 19:01:06 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 19:10:25 GMT]]></title><description><![CDATA[<p>Wenn ich mich mal einmischen dürfte, ich finde dass die Frage nicht so sinnlos ist, schließlich sollte man bei seinen Bestrebungen die Tatsache, dass C++11 stateful allocators erlaubt nicht auslassen. Desweiteren, eigentlich sollte ein allocator, sollte er den <a href="http://en.cppreference.com/w/cpp/concept/Allocator" rel="nofollow">Anforderungen für Allokatoren</a> entsprechen, kopierbar sein, das heißt man kann einen allocator eines Typs konstruieren mit dem allocator eines anderen Typs, vorrausgesetzt es handelt sich um denselben allocator (z.B. std::allocator&lt;int&gt; und std::allocator&lt;float&gt;)</p>
<p>PS: Du speicherst also den alten allocator, und konstruierst damit ständig einen neuen, der dafür geeignet ist. Spricht etwas dagegen intern einen allocator&lt;node&lt;int&gt; &gt; zu speichern und wann immer get_allocator aufgerufen wird, einen allocator&lt;int&gt; von dem internen allocator zu konstruieren? So oft wird das ja nicht passieren, im Vergleich zu einer allocation</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334641</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334641</guid><dc:creator><![CDATA[Flashput]]></dc:creator><pubDate>Wed, 26 Jun 2013 19:10:25 GMT</pubDate></item><item><title><![CDATA[Reply to allocator und list-implementierung on Wed, 26 Jun 2013 21:17:03 GMT]]></title><description><![CDATA[<p>Wenn geht sollten mMn. immer alle benötigten Allokatoren als Member abgelegt sein.<br />
Wobei das bei klassischen Containern eh nur einige wenige sein sollten.</p>
<p>Blöd wird's z.B. bei nem Container der erlaubt abgeleitete Klassen &quot;by value&quot; reinzustecken. Mit ner verketteten Liste ginge das z.B. recht einfach. Da dort <code>push_back</code> aber ein Template ist, und mit beliebig vielen Typen funktioniert, kann man natürlich nicht mehr einfach alle Allokatoren aufheben. Bzw. man könnte schon, aber dann müsste man die wieder in irgend einem Container halten, und ob der Lookup dann billiger ist als den Allokator &quot;just in time&quot; zu erzeugen ist die Frage...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2334671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2334671</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 26 Jun 2013 21:17:03 GMT</pubDate></item></channel></rss>