Skip to main content
gamedev.net
🔒 Locked

Small Memcpy Issue

Started by Permafried- Jul 8, 2004 at 5:55 PM 4 replies 500+ views
Original Post
Permafried-
Permafried-
Hello, I'm currently in the process of creating a final message to be sent out from my server to my client in my networked game. In essence what I'm doing is taking the reliable and unreliable portions of the message and copying them over to a final message which will be passed to my network layer and sent. I'm trying to use memcpy() to copy the contents of one unsigned char buffer to the next using an index and then bump up the index after the copy to get ready for the unreliable portion of the message if there is one. My code looks like the following:

   // add the reliable message to the buffer
   memcpy( &send.m_szData[ iIndex ], 
   &m_pClients[ i ]->m_storedReliableMessage.m_szData,
    m_pClients[ i ]->m_storedReliableMessage.m_iCurrentSize );

   // bump up the current size of the message
   send.m_iCurrentSize += m_pClients[ i ]->  
   m_storedReliableMessage.m_iCurrentSize;
Unfortunately, when this message gets to the client, my message has not been copied over correctly as all I end up with on the client side current is a C8 which appears to be part of a memory address. I'm hoping someone here can point me in the right direction because I can't seem to figure out what's wrong at this point. Thanks in advance, Permafried-
tomek_zielinski
tomek_zielinski
memcpy( &send.m_szData[ iIndex ],   // <=here you are indexing m-szData   &m_pClients[ i ]->m_storedReliableMessage.m_szData, // here you are not indexing m_szData - so probalby you are taking address of a poiter, so a pointer is copied    m_pClients[ i ]->m_storedReliableMessage.m_iCurrentSize );


m_sz - if it's hungarian notation then it's null-terminated string, so you don't really want to take its address, so delete ampersand
www.tmreality.com
Permafried-
Permafried-
Hey,

I might have mislead you in what I'm trying to do here. First of all, my m_szData is declared as follows in my CMessage.hpp:

unsigned char* m_szData

Then, in CMessage.cpp in my default ctor I make a call to new as follows:

m_szData = new unsigned char[ 4096 ];

Sorry about the naming conventions, I recently made some changes to types etc. and may not have updated all my names yet to reflect those data type changes.

Basically I'm trying to copy the contents of the client's m_szData into the send.m_szData starting at iIndex to reliableMessage.currentSize.

Then, when it comes time to copy over the unreliable message I want to make a similar call starting at the current iIndex up to the current size of the unreliable message.

In short, I'm trying to take the contents of the reliable and unreliable buffers and combine them into one final buffer which will be passed through to be sent via my network layer.

Hope this clears things up a bit,

Permafried-
tomek_zielinski
tomek_zielinski
So - if I'm not overlooking sth I was right? But it's 1:57AM at my place...

&send.m_szData[ iIndex ] -> address of 'iIndex' byte of send

&m_pClients[ i ]->m_storedReliableMessage.m_szData -> address od pointer, because m_szData IS a pointer. You probably wanted to do "&m_pClients[ i ]->m_storedReliableMessage.m_szData[0]" or "m_pClients[ i ]->m_storedReliableMessage.m_szData"???



www.tmreality.com
silvermace
silvermace
yes they above posters are correct, you are taking the ADDRESSOF the string POINTER, not the ADDRESSOF the string

so your actually passing in a 'pointer to a pointer' instead of a 'pointer'
Permafried-
Permafried-
Hey all,

Thanks for the replies, you'd think it was 1:30 in the morning here, talk about a major brain fart.....you were of course right and thanks a lot it's solved my problem....reliable packet transmissions are now working ^_^.

Permafried-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.