* @brief Implementation of @c limitSystemMemory() on Windows. */
| 78 | * @brief Implementation of @c limitSystemMemory() on Windows. |
| 79 | */ |
| 80 | bool limitSystemMemoryOnWindows(std::size_t limit) { |
| 81 | // On Windows 7, AssignProcessToJobObject() fails when the current process |
| 82 | // has already been attached to a job. Therefore, we have to remember the |
| 83 | // job and use it in all subsequent calls to limitSystemMemoryOnWindows(). |
| 84 | // This is not thread safe, but limitSystemMemory() is already marked as |
| 85 | // not reentrant, so we are OK. |
| 86 | static auto jobHandle = assignProcessToNewJob(); |
| 87 | |
| 88 | JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo{}; |
| 89 | extendedInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY; |
| 90 | extendedInfo.ProcessMemoryLimit = limit; |
| 91 | |
| 92 | auto succeeded = SetInformationJobObject( |
| 93 | jobHandle, |
| 94 | JobObjectExtendedLimitInformation, |
| 95 | &extendedInfo, |
| 96 | sizeof(extendedInfo) |
| 97 | ); |
| 98 | return succeeded; |
| 99 | } |
| 100 | |
| 101 | #elif defined(OS_MACOS) |
| 102 |
no test coverage detected