MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / lockMemoryResident

Function lockMemoryResident

app/src/Platform/AppPlatform.cpp:579–611  ·  view source on GitHub ↗

* @brief Pins @p len bytes at @p ptr into physical memory (best effort): page-fault stalls on * the frame-scan buffers become latency spikes at rate. Returns true when pinned. */

Source from the content-addressed store, hash-verified

577 * the frame-scan buffers become latency spikes at rate. Returns true when pinned.
578 */
579bool lockMemoryResident(const void* ptr, size_t len)
580{
581 Q_ASSERT(ptr != nullptr);
582 Q_ASSERT(len > 0);
583
584 if (!ptr || len == 0) [[unlikely]]
585 return false;
586
587#if defined(Q_OS_WIN)
588 void* base = const_cast<void*>(ptr);
589 if (VirtualLock(base, len))
590 return true;
591
592 SIZE_T minWs = 0;
593 SIZE_T maxWs = 0;
594 if (!GetProcessWorkingSetSize(GetCurrentProcess(), &minWs, &maxWs))
595 return false;
596
597 const SIZE_T slack = 2u * 1024u * 1024u;
598 const SIZE_T newMin = minWs + len + slack;
599 const SIZE_T newMax = (maxWs > newMin + slack) ? maxWs : (newMin + slack);
600 if (!SetProcessWorkingSetSize(GetCurrentProcess(), newMin, newMax))
601 return false;
602
603 return VirtualLock(base, len) != 0;
604#elif defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
605 return mlock(ptr, len) == 0;
606#else
607 Q_UNUSED(ptr);
608 Q_UNUSED(len);
609 return false;
610#endif
611}
612
613/**
614 * @brief Registers the calling (ingest/main) thread with MMCSS "Pro Audio"; call only after the

Callers 2

makeStorageMethod · 0.85
FrameReaderMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected