2025-02-19 20:22:30 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
2025-03-06 22:22:48 +00:00
|
|
|
#include <Windows.h>
|
2025-02-19 20:22:30 +03:00
|
|
|
#else
|
2025-03-06 22:22:48 +00:00
|
|
|
#include <sys/mman.h>
|
2025-02-19 20:22:30 +03:00
|
|
|
#endif
|
|
|
|
|
2025-03-06 22:22:48 +00:00
|
|
|
struct MemoryMappedFile
|
|
|
|
{
|
2025-02-19 20:22:30 +03:00
|
|
|
#if defined(_WIN32)
|
|
|
|
HANDLE fileHandle = nullptr;
|
|
|
|
HANDLE fileMappingHandle = nullptr;
|
|
|
|
LPVOID fileView = nullptr;
|
|
|
|
LARGE_INTEGER fileSize = {};
|
|
|
|
#else
|
|
|
|
int fileHandle = -1;
|
2025-03-06 22:22:48 +00:00
|
|
|
void* fileView = MAP_FAILED;
|
2025-02-19 20:22:30 +03:00
|
|
|
off_t fileSize = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MemoryMappedFile();
|
2025-03-06 22:22:48 +00:00
|
|
|
MemoryMappedFile(const std::filesystem::path& path);
|
|
|
|
MemoryMappedFile(MemoryMappedFile&& other);
|
2025-02-19 20:22:30 +03:00
|
|
|
~MemoryMappedFile();
|
2025-03-06 22:22:48 +00:00
|
|
|
bool open(const std::filesystem::path& path);
|
2025-02-19 20:22:30 +03:00
|
|
|
void close();
|
|
|
|
bool isOpen() const;
|
2025-03-06 22:22:48 +00:00
|
|
|
uint8_t* data() const;
|
2025-02-19 20:22:30 +03:00
|
|
|
size_t size() const;
|
|
|
|
};
|