#### Archived

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

# Splitting a buffer of data into sections...

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

## 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;
//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 on other sites
// 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 on other sites
Thanks - I''ll give it a try.