I am trying to sort a buffer using STL sort. Now, Im using qsort but i read that stlsort has a better performance because of the inline "compare" function. The buffer has elements of size 52. It has, for example, 1024 elements of size 52. Here is a part of my code. It is working well, but I want to use the STL sort. I am sorting a fixed length file. Each fixed length file has a record size, so the user has to inform the record size. In the example below i put 52.
HANDLE hInFile;
char * sharedBuffer;
int recordSize = 52;
sharedBuffer = new char [totalMemory];
hInFile = CreateFile(LPCSTR(filePathIn), GENERIC_READ, 0, NULL, OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN, NULL);
ReadFile(hInFile, sharedBuffer, totalMemory, &dwBytesRead, NULL);
CloseHandle(hInFile);
qsort(sharedBuffer, dwBytesRead/recordSize, recordSize, compare); //sort using qsort but i want to use the slt sort
WriteFile(hOutFile, sharedBuffer, dwBytesRead, &dwBytesRead, NULL);
CloseHandle(hOutFile); //write the sorted buffer to disk
int compare (const void * a, const void * b)
{
return memcmp((char *)a, (char *)b, recordSize);
}
Can i read the file in other way? Using a vector, iterators?
Thanks for the help!