<?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[Suche strcpy, strcmp, memcpy, memcmp Implementation]]></title><description><![CDATA[<p>Hi, wo finde ich denn die Implementationen von den Funktionen strcpy, strcmp, memcpy und memcmp? Kann mir da jemand weiterhelfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/290637/suche-strcpy-strcmp-memcpy-memcmp-implementation</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 07:15:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/290637.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 31 Jul 2011 01:05:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 01:05:25 GMT]]></title><description><![CDATA[<p>Hi, wo finde ich denn die Implementationen von den Funktionen strcpy, strcmp, memcpy und memcmp? Kann mir da jemand weiterhelfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099957</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099957</guid><dc:creator><![CDATA[Implementator]]></dc:creator><pubDate>Sun, 31 Jul 2011 01:05:25 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 02:19:52 GMT]]></title><description><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Strcmp" rel="nofollow">http://en.wikipedia.org/wiki/Strcmp</a><br />
<a href="http://en.wikipedia.org/wiki/Strcpy" rel="nofollow">http://en.wikipedia.org/wiki/Strcpy</a><br />
<a href="http://clc-wiki.net/wiki/memcpy" rel="nofollow">http://clc-wiki.net/wiki/memcpy</a><br />
<a href="http://clc-wiki.net/wiki/memcmp" rel="nofollow">http://clc-wiki.net/wiki/memcmp</a></p>
<p>Im Übrigen sind gerade die copy Funktionen bei den meisten Compilern direkt in Assembler geschrieben. Willst du dafür auch Beispiele? (Und das hier ist das C++-Forum, in dem du nach C Funktionen fragst. Kannst also gleich schon mal schreiben, ob du lieber in das C oder in das Assembler Forum geschoben werden willst.)</p>
<p>Edit:</p>
<blockquote>
<p>die Implementationen</p>
</blockquote>
<p>&quot;Die Implementierungen&quot; gibt es nicht, das kann jeder Compiler so machen, wie er will. (Solange es funktioniert. Der Standard gibt nur vor, was die Funktionen machen müssen; <strong>nicht</strong> wie.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099959</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099959</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sun, 31 Jul 2011 02:19:52 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 08:46:39 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Der Standard gibt nur vor, was die Funktionen machen müssen; <strong>nicht</strong> wie.)</p>
</blockquote>
<p>und bei manchen dingen auch mit welcher geschwindigkeit/komplexität...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099979</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099979</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sun, 31 Jul 2011 08:46:39 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 08:58:14 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>und bei manchen dingen auch mit welcher geschwindigkeit/komplexität...</p>
</blockquote>
<p>Z.B.?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099981</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099981</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 31 Jul 2011 08:58:14 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 09:06:49 GMT]]></title><description><![CDATA[<p>also der standard sagt bei den containern was über die komplexität aus<br />
ich meine map und set dürften maximal logarithmische komplexität besitzen. da müsste man mal nachgucken, hab das mal gelesen irgendwo</p>
<p>edit: <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2011/n3242.pdf" rel="nofollow">STD § 23.2.4</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099982</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099982</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sun, 31 Jul 2011 09:06:49 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 09:03:56 GMT]]></title><description><![CDATA[<p>Bei vielen Algorithmen und den Containerklassen werden Laufzeit-Klassen vorgegeben (z.B. O(n log n) für std::sort() oder O(log n) für map/set-Operationen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099983</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099983</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sun, 31 Jul 2011 09:03:56 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 09:12:15 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>Bei vielen Algorithmen und den Containerklassen werden Laufzeit-Klassen vorgegeben (z.B. O(n log n) für std::sort() oder O(log n) für map/set-Operationen).</p>
</blockquote>
<p>Im N1905 habe ich die Komplexität für die assoziativen Container gefunden, nicht aber für <code>std::sort</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099984</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099984</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 31 Jul 2011 09:12:15 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 09:37:37 GMT]]></title><description><![CDATA[<p>Ich hab' leider keinen aktuellen Standard verfügbar, aber im Josuttis sind die Komplexitätsanforderungen für diverse Algorithmen aufgelistet, z.B.:</p>
<p>sort/stable_sort schrieb:</p>
<blockquote>
<p>Complexity:<br />
- for <code>sort()</code> : n-log-n on average (approximately <em>numberOfElements**log(<em>numberOfElements</em>) comparisions on average)<br />
- for <code>stable_sort()</code> : n-log-n if there is enough extra memory (...), or n-log-n</em>log-n otherwise</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2099990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099990</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Sun, 31 Jul 2011 09:37:37 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 09:45:55 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Im N1905 habe ich die Komplexität für die assoziativen Container gefunden, nicht aber für <code>std::sort</code> .</p>
</blockquote>
<p>25.3.1.1.3</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099994</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099994</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 31 Jul 2011 09:45:55 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 09:49:19 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>25.3.1.1.3</p>
</blockquote>
<p>Hab ich übersehen. Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2099998</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2099998</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Sun, 31 Jul 2011 09:49:19 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 10:07:17 GMT]]></title><description><![CDATA[<p>Implementator schrieb:</p>
<blockquote>
<p>Hi, wo finde ich denn die Implementationen von den Funktionen strcpy, strcmp, memcpy und memcmp?</p>
</blockquote>
<p>Bei anderen weiß ich es nicht, aber memcpy ist beim GCC eine vieler &quot;intrinsischer Funktionen&quot;. Das heißt, es gibt höchstens eine C-Version als Fallback irgendwo in den Headern oder der libc.</p>
<p>Werfe ich das dem GNU C++ Compiler zum Fraß vor...</p>
<pre><code class="language-cpp">// g++ -c -O2 memcpy.cpp

#include &lt;cstring&gt;

void foo(void* t, void const* s, std::size_t len)
{
  std::memcpy(t,s,len);  
}
</code></pre>
<p>...und disassembliere das Resultat per objdump, dann erhalte ich das hier:</p>
<pre><code>// objdump -Cd memcpy.o

memcpy.o:     file format pe-i386

Disassembly of section .text:

00000000 &lt;foo(void*, void const*, unsigned int)&gt;:
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	57                   	push   %edi
   4:	56                   	push   %esi
   5:	8b 45 08             	mov    0x8(%ebp),%eax
   8:	8b 75 0c             	mov    0xc(%ebp),%esi
   b:	8b 4d 10             	mov    0x10(%ebp),%ecx
   e:	89 c7                	mov    %eax,%edi
  10:	f3 a4                	rep movsb %ds:(%esi),%es:(%edi)
  12:	5e                   	pop    %esi
  13:	5f                   	pop    %edi
  14:	c9                   	leave  
  15:	c3                   	ret    
  16:	90                   	nop
  17:	90                   	nop
</code></pre>
<p>So. Da hast Du die Implementierung von std::memcpy. <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/2100004</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2100004</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 31 Jul 2011 10:07:17 GMT</pubDate></item><item><title><![CDATA[Reply to Suche strcpy, strcmp, memcpy, memcmp Implementation on Sun, 31 Jul 2011 11:11:27 GMT]]></title><description><![CDATA[<p>Ganz interessant finde ich in dem Zusammenhang auch, dass der Compiler (MSVC) statt in einer Schleife direkt kopiert und dabei die Registerbreite ausnutzen kann (nur bis zu einer bestimmten Größe, und auch nur, wenn die Größe % Registerbreite == 0).<br />
24 Byte kopieren auf einem 32 Bit-System:</p>
<pre><code>mov	edx, DWORD PTR [eax]
	mov	DWORD PTR [ecx], edx
	mov	edx, DWORD PTR [eax+4]
	mov	DWORD PTR [ecx+4], edx
	mov	edx, DWORD PTR [eax+8]
	mov	DWORD PTR [ecx+8], edx
	mov	edx, DWORD PTR [eax+12]
	mov	DWORD PTR [ecx+12], edx
	mov	edx, DWORD PTR [eax+16]
	mov	DWORD PTR [ecx+16], edx
	mov	eax, DWORD PTR [eax+20]
	mov	DWORD PTR [ecx+20], eax
</code></pre>
<p>Mit SSE-Optimierungen werden stattdessen die XMM Register bemüht:</p>
<pre><code>movq	xmm0, QWORD PTR [eax]
	movq	QWORD PTR [ecx], xmm0
	movq	xmm0, QWORD PTR [eax+8]
	movq	QWORD PTR [ecx+8], xmm0
	movq	xmm0, QWORD PTR [eax+16]
	movq	QWORD PTR [ecx+16], xmm0
</code></pre>
<p>Bei anderen (geraden) Längen zieht der Compiler mit den Optimierungen die XMM- und für das letzte Wort das ax-Register heran.</p>
<p>Ähnliche Optimierungen kommen auch bei strcmp und Konsorten zum Zuge*. Nur die naivsten Implementierungen (gibt es soetwas überhaupt noch?) vergleichen byteweise.</p>
<p>Edit: Bzw. diese Funktionen werden gleich so programmiert. seldon hat dies afair einmal im C-Forum demonstriert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2100019</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2100019</guid><dc:creator><![CDATA[yahendrik]]></dc:creator><pubDate>Sun, 31 Jul 2011 11:11:27 GMT</pubDate></item></channel></rss>