I have used MapVirtualFile to map a file under Window using C++ VS2010. The void is
void* m_pVoiceData;
I would now like to fill a structure with the data.
I have been using
void clsMapping::FeedPitchmarksFromMap(udtPitchmarks &uAudioInfo,unsigned long int uBytePos)
{
unsigned long int iCountPM;
memcpy(&iCountPM, &((char*)(m_pVoiceData))[uBytePos],sizeof(int));
uAudioInfo.Pitchmarks.resize(iCountPM);
for (unsigned long int i=0;i<iCountPM;i++)
{
iBytePos+=sizeof(int);
unsigned long int iByteStart;
memcpy(&iByteStart, &((char*)(m_pVoiceData))[iBytePos],4);
iBytePos+=sizeof(int);
unsigned long int iByteCount;
memcpy(&iByteCount, &((char*)(m_pVoiceData))[iBytePos],4);
iBytePos+=sizeof(int);
unsigned int iF0;
memcpy(&iF0, &((char*)(m_pVoiceData))[iBytePos],4);
uAudioInfo.Pitchmarks[i].ByteStart =iByteStart;
uAudioInfo.Pitchmarks[i].ByteCount =iByteCount;
uAudioInfo.Pitchmarks[i].F0 =iF0;
}
}
As one can see, I am currently using memcpy to get the data. Is there a faster way to do "get my data over"?
The "fastest" would probably be simple assignment:
unsigned long iCountPM =
*reinterpret_cast<unsigned long*>(reinterpret_cast<char*>(m_pVoiceData) + uBytePos);
Can be used instead for all those memcpy
calls in the function.