<?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[verschiedene Variablen in char[] packen]]></title><description><![CDATA[<p>ich bin auf der Suche nach schnellem Algorythmus, die mir z.B. mehrere int Variablen in eine char[] packt.<br />
Dieses Format brauche ich, um sie über eine Socket- Verbindung zu schicken.</p>
<p>hab eigetlich vor gehabt, die int's temporär in CString zu casten, dann alle addieren und schließlich</p>
<pre><code>CString strTemp = &quot;Variablen nach der Umwandlung in CString&quot;;
int bufferSize = strTemp.GetLenght() + 1;
char* pBuffer = new char [ bufferSize ];
sprintf(pBuffer, _T(&quot;%s\0&quot;), strTemp);

socket.Send (buffer, bufferSize, 0); // sende über Socket Verbindung

delete pBuffer;
</code></pre>
<p>Gibts es besseres, oder anders ausgedruckt etwas schnelleres ?<br />
z.B. ohne den CString (wegen Kon-und Destruktion des Objektes)</p>
<p>Hat jemand Idee ?<br />
Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/131376/verschiedene-variablen-in-char-packen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 03:56:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/131376.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Jan 2006 02:03:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Tue, 03 Jan 2006 02:03:31 GMT]]></title><description><![CDATA[<p>ich bin auf der Suche nach schnellem Algorythmus, die mir z.B. mehrere int Variablen in eine char[] packt.<br />
Dieses Format brauche ich, um sie über eine Socket- Verbindung zu schicken.</p>
<p>hab eigetlich vor gehabt, die int's temporär in CString zu casten, dann alle addieren und schließlich</p>
<pre><code>CString strTemp = &quot;Variablen nach der Umwandlung in CString&quot;;
int bufferSize = strTemp.GetLenght() + 1;
char* pBuffer = new char [ bufferSize ];
sprintf(pBuffer, _T(&quot;%s\0&quot;), strTemp);

socket.Send (buffer, bufferSize, 0); // sende über Socket Verbindung

delete pBuffer;
</code></pre>
<p>Gibts es besseres, oder anders ausgedruckt etwas schnelleres ?<br />
z.B. ohne den CString (wegen Kon-und Destruktion des Objektes)</p>
<p>Hat jemand Idee ?<br />
Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/955277</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/955277</guid><dc:creator><![CDATA[Roman007]]></dc:creator><pubDate>Tue, 03 Jan 2006 02:03:31 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Tue, 03 Jan 2006 11:56:57 GMT]]></title><description><![CDATA[<p>Roman007 schrieb:</p>
<blockquote>
<pre><code>[...]
char* pBuffer = new char [ bufferSize ];
[...]
delete pBuffer;
</code></pre>
</blockquote>
<pre><code class="language-cpp">delete [] pBuffer;
</code></pre>
<p>Nicht vergessen:<br />
Array-zu-Array und Staub-zu-Staub <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/955481</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/955481</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Tue, 03 Jan 2006 11:56:57 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Tue, 03 Jan 2006 14:19:07 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{
    int a = 0, b = 1234, c = -654321;
    char SendCString[3 * sizeof(int)];
    memcpy(SendCString + 0, reinterpret_cast&lt;char*&gt;(&amp;a), sizeof(int));
    memcpy(SendCString + 4, reinterpret_cast&lt;char*&gt;(&amp;b), sizeof(int));
    memcpy(SendCString + 8, reinterpret_cast&lt;char*&gt;(&amp;c), sizeof(int));        
    // Hier kann der SendCString dann gesendet werden.
    // Der folgende Code wird dann beim Empfänger ausgeführt:
    int a2, b2, c2;
    a2 = *(reinterpret_cast&lt;int*&gt;(SendCString + 0));
    b2 = *(reinterpret_cast&lt;int*&gt;(SendCString + 4));
    c2 = *(reinterpret_cast&lt;int*&gt;(SendCString + 8));        
    cout &lt;&lt; a2 &lt;&lt; endl &lt;&lt; b2 &lt;&lt; endl &lt;&lt; c2;
    cin.get();
    return 0;
}
</code></pre>
<p>edit: warumkannichlängeretextenichtmehrschreiben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/955623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/955623</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Tue, 03 Jan 2006 14:19:07 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Tue, 03 Jan 2006 14:21:00 GMT]]></title><description><![CDATA[<p>edit: das ist jetzt zu meinem post davor, weil zusammen will geht's irgentwie nciht. (siehe ps)</p>
<p>Deine Vorgehensweise hab ich irgentwie nicht vestanden.</p>
<p>Ich hab allerdings gehört, dass der reinterpret_cast von einigen Compilier falsch implementiert wird, bei mir (MinGW) hat's allerdings geklappt.</p>
<p>Ich hab den CString jetzt auf dem Stack erstellt, wenn du ihn auf dem Heap erstellen willst, empfehle ich die das shared_array Templete von der boost Library. Ich hab's jetzt aber nicht benutzt damit es einfacher ist.</p>
<p>mfg.</p>
<p>ps: Irgentwie kann ich nur ab und zu was antworten. Ich klick auf den absenden button und dann passiert gar nichts. nach ner zeit kommt dann, dass die verbindung vom server zurück gesetzt wurde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/955628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/955628</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Tue, 03 Jan 2006 14:21:00 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Tue, 03 Jan 2006 14:31:04 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;boost/serialization.hpp&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;

std::ostringstream stream;
boost::archive::text_oarchive out (stream);

out &lt;&lt; data1;
out &lt;&lt; data2;
// etc.

std::string str = stream.str ();

socket.Send (str.c_str (), str.length (), 0); // sende über Socket Verbindung
</code></pre>
<p>Siehe <a href="http://www.boost.org/libs/serialization/doc/index.html" rel="nofollow">http://www.boost.org/libs/serialization/doc/index.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/955649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/955649</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Tue, 03 Jan 2006 14:31:04 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Tue, 03 Jan 2006 22:49:08 GMT]]></title><description><![CDATA[<p>Danke Leute,<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/110">@HumeSikkins</a><br />
hast natürlich recht, schnell getippt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6950">@joomoo</a><br />
sieht interessant aus, muss ich wohl probieren, wie schnell es ist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /><br />
Dekodieren brauche ich nicht, die Daten werden an Java-Applet gesendet, da gibt Standard-Methode, die sich darum kümmert.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/9606">@.filmor</a><br />
davon habe ich nicht gehört, schau mir mal genauer an</p>
<p>THX</p>
]]></description><link>https://www.c-plusplus.net/forum/post/956194</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956194</guid><dc:creator><![CDATA[Roman007]]></dc:creator><pubDate>Tue, 03 Jan 2006 22:49:08 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Wed, 04 Jan 2006 10:15:33 GMT]]></title><description><![CDATA[<p>Ich nahm an, dass du es an ein C++ Programm sendest, aber Java hat doch AFAIK ziemlich gute XML-Unterstützung, oder? Dann wäre möglicherweise</p>
<pre><code class="language-cpp">boost::archive::xml_oarchive
</code></pre>
<p>angebrachter. Ist bestimmt einfacher, als einen Text zu parsen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/956381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956381</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Wed, 04 Jan 2006 10:15:33 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Wed, 04 Jan 2006 10:24:40 GMT]]></title><description><![CDATA[<p><a href="http://en.wikipedia.org/wiki/XDR" rel="nofollow">http://en.wikipedia.org/wiki/XDR</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/956392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956392</guid><dc:creator><![CDATA[c.rackwitz]]></dc:creator><pubDate>Wed, 04 Jan 2006 10:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Wed, 04 Jan 2006 18:08:41 GMT]]></title><description><![CDATA[<p>Hallo,<br />
in Java läßt sich aus dem serialisierten Stream einfach die Variablen auslesen:</p>
<pre><code class="language-java">[code]
int a = DataInputStream.readInt(); // liest erste Zeichenfolge bis Leezeichen als int ein
DataInputStream.readChar(); // Überspringt das Leerzeichen 
//u.s.w.
[/code]
</code></pre>
<p>Es gibt Methoden für diverse Typen. Einfacher geht nicht! Oder? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /><br />
dafür ist das hier das falsches Forum, aber gehört eben zum Thread.</p>
<p>So eine Klasse wünschte ich mir auch in c++ <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="😃"
    /></p>
<p>Roman</p>
]]></description><link>https://www.c-plusplus.net/forum/post/956959</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956959</guid><dc:creator><![CDATA[Roman007]]></dc:creator><pubDate>Wed, 04 Jan 2006 18:08:41 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Wed, 04 Jan 2006 18:28:45 GMT]]></title><description><![CDATA[<p>Roman007 schrieb:</p>
<blockquote>
<p>Hallo,<br />
in Java läßt sich aus dem serialisierten Stream einfach die Variablen auslesen:</p>
<pre><code class="language-java">[code]
int a = DataInputStream.readInt(); // liest erste Zeichenfolge bis Leezeichen als int ein
DataInputStream.readChar(); // Überspringt das Leerzeichen 
//u.s.w.
[/code]
</code></pre>
<p>Es gibt Methoden für diverse Typen. Einfacher geht nicht! Oder? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /><br />
dafür ist das hier das falsches Forum, aber gehört eben zum Thread.</p>
<p>So eine Klasse wünschte ich mir auch in c++ <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="😃"
    /></p>
<p>Roman</p>
</blockquote>
<p>Das ist zwar einfach, aber es ist langsam und uneffizent. Ein int kann bis zu 4 millarden gehen, also 10 Stellen. Das wäre, wenn du das ganze über diese Methode schickst 10 Byte + 1 Byte für das Leerzeichen. Und wenn du heiß auf Schnelligkeit bist, ist dies bestimmt die schlechteste Möglichkeit. Die Methode, das int binär zu senden, verbraucht weniger traffic und ist schneller, also effizienter. Dort würde ein int immer 4 Byte verbrauchen, und wenn du int nimmst, darf man davon ausgehen dass du auch mehr als 3 Stellen hast.</p>
<p>Ich hoffe ich hab die Java Funktionen richtig verstanden. Für mich sieht das aus wie sscanf.</p>
<p>mfg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/956988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956988</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Wed, 04 Jan 2006 18:28:45 GMT</pubDate></item><item><title><![CDATA[Reply to verschiedene Variablen in char[] packen on Wed, 04 Jan 2006 18:36:29 GMT]]></title><description><![CDATA[<p>edit: Doppelpost. Keine Ahnung warum.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/956990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956990</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Wed, 04 Jan 2006 18:36:29 GMT</pubDate></item></channel></rss>