Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

jack_1313

Splitting a buffer of data into sections...

This topic is 5330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. First, I’d like to point out that I am reposting this question in the General Programming forum (previously posted in the Multiplayer and Networking section) as I did not reach a solution and do not believe the issue is networking-specific (would have been faster to post here in the first place). For those that wish to view the original post, it can be seen here. To put it plainly, I have a PBYTE buffer of data that I wish to split into two sections. I need to take the first piece of data in the buffer the size of DWORD and store it, then place the remaining data in another PBYTE. The first step is simple enough – it can be done with a single call to memcpy(). The second part has me puzzled – I need to memcpy() from an offset inside the buffer (ignore the first however many bytes (size of DWORD) and then start copying from there) – how is this done? It is worth noting that I do know the size of the whole data buffer. Here is what I have (pMsg->pReceiveData is the PBYTE buffer):
DWORD Id;
PBYE Data;
memcpy( &Id, pMsg->pReceiveData, sizeof(DWORD) );
memcpy( Data, SIZEOF(DWORD) INTO THE pMsg->pReceiveData, pMsg->pReceiveDataSize - sizeof(DWORD) );
//Need to ignore the first piece of data the size of DWORD and

//start copying from beyond that point

Any help would be great. Come to think of it, can I do: memcpy( Data, (pMsg->pReceiveData+sizeof(DWORD)), pMsg->pReceiveDataSize - sizeof(DWORD) ); ? Would that work? I’ve typed this now so I may as well post it . Thanks for your time.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
// Get data size seperate.
DWORD dwDataSize = pMsg->pReceiveDataSize - sizeof(DWORD);
// Allocate destination buffer for source data to be copied.
CHAR* pcDestination = new CHAR[dwDataSize];
// Get an offset into the source data section.
CHAR* pcSource = (CHAR*)(((CHAR*)pMsg->pReceiveData) + sizeof(DWORD));
memcpy(pcDestination,pcSource,dwDataSize);
// And that should do it.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!