In my code I save data in a binary file, when I save I run the function save()
in a different thread. The data that I'm saving are stored in a vector<uint_32>
, this vector is used also by others function and I did a copy to avoid conflicts and not desired modification, I think that this isn't the most efficient way to solve this problem so I want ask which is the best way to have this kind of behavior? I was thinking about shared pointers, maybe.
here is the code:
inline void write( std::vector<uint32_t > pData ) {
fThread = std::thread( &FileHandler::writeFile, this, pData );
fThread.join();
}
inline void writeFile( std::vector<uint32_t> cVectorCopy ) {
fwrite( ( char* )&cVectorCopy[0] , cVectorCopy.size()*sizeof( uint32_t ) , 1, fBinaryFile );
closeFile();
}