MCPcopy Create free account
hub / github.com/Tencent/MMKV / mmapOrCleanup

Method mmapOrCleanup

Core/MemoryFile_Win32.cpp:197–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197bool MemoryFile::mmapOrCleanup(FileLock *fileLock) {
198 auto mode = m_readOnly ? PAGE_READONLY : PAGE_READWRITE;
199 m_fileMapping = CreateFileMapping(m_diskFile.getFd(), nullptr, mode, 0, 0, nullptr);
200 if (!m_fileMapping) {
201 MMKVError("fail to CreateFileMapping [%s], mode %x, %d", m_diskFile.getUTF8Path().c_str(), mode,
202 GetLastError());
203 return false;
204 } else {
205 auto viewMode = m_readOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS;
206 m_ptr = (char*)MapViewOfFile(m_fileMapping, viewMode, 0, 0, 0);
207 if (!m_ptr) {
208 MMKVError("fail to mmap [%s], mode %x, %d", m_diskFile.getUTF8Path().c_str(), viewMode, GetLastError());
209
210 doCleanMemoryCache(true);
211 return false;
212 }
213 MMKVInfo("mmap to address [%p], [%s]", m_ptr, m_diskFile.getUTF8Path().c_str());
214
215 if (m_isMayflyFD && fileLock) {
216 fileLock->destroyAndUnLock();
217 }
218
219 cleanMayflyFD();
220 return true;
221 }
222}
223
224void MemoryFile::reloadFromFile(size_t expectedCapacity) {
225 if (isFileValid()) {

Callers

nothing calls this directly

Calls 2

destroyAndUnLockMethod · 0.80
getFdMethod · 0.45

Tested by

no test coverage detected