Skip to content

Instantly share code, notes, and snippets.

@corporateshark
Last active January 10, 2024 10:08
Show Gist options
  • Save corporateshark/9b6b5d566cc1b4c55a18b44fdcf96033 to your computer and use it in GitHub Desktop.
Save corporateshark/9b6b5d566cc1b4c55a18b44fdcf96033 to your computer and use it in GitHub Desktop.
Sort Huge Files
#include <stdint.h>
#include <windows.h>
#include <algorithm>
int main() {
HANDLE handleFile = CreateFileA("E:/1/build/001114-0452-03.jpg",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
HANDLE handleMap = CreateFileMapping(handleFile,
NULL,
PAGE_READWRITE,
0,
0,
NULL);
DWORD dwSizeHigh = 0;
DWORD dwSizeLow = GetFileSize(handleFile, &dwSizeHigh);
const uint64_t size = ((uint64_t)dwSizeHigh << 32u) | (uint64_t)dwSizeLow;
uint8_t* data = static_cast<uint8_t*>(MapViewOfFile(handleMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0));
std::sort(data, data + size);
UnmapViewOfFile(data);
CloseHandle(handleMap);
CloseHandle(handleFile);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment