33 lines
875 B
C++
33 lines
875 B
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "MemMappedFile.hpp"
|
|
#include "Base/Logger.hpp"
|
|
#include "MemMappedFileInternal.hpp"
|
|
|
|
namespace OpenVulkano
|
|
{
|
|
MemMappedFile::MemMappedFile(const std::filesystem::path& path, FileMode fileMode)
|
|
: m_data(nullptr), m_size(0)
|
|
{
|
|
std::string file = path.string();
|
|
m_internal = std::make_shared<MemMappedFileInternal>(file.c_str(), fileMode);
|
|
m_data = m_internal->address;
|
|
m_size = (m_data) ? m_internal->size : 0;
|
|
}
|
|
|
|
void MemMappedFile::Close()
|
|
{
|
|
if (m_internal.use_count() != 1)
|
|
{
|
|
Logger::APP->warn("Closing memory mapped file with {} usages", m_internal.use_count());
|
|
}
|
|
m_internal = nullptr;
|
|
m_data = nullptr;
|
|
m_size = 0;
|
|
}
|
|
}
|