Skip to content

armgit / WSM

Public Imported from GitHub
0

Run macOS applications on your Windows desktop, with a background runtime and integrated app windows.

C++
1014 B
Raw Blame
#pragma once
#include <cstdint>
#include <sstream>
#include <string>

namespace wsm::runtime {
inline uint64_t setup_memory_mib(uint64_t host_mib, const std::string& config = {}) {
    std::istringstream lines(config);
    for (std::string line; std::getline(lines, line);) {
        const auto eq = line.find('=');
        if (eq == std::string::npos) continue;
        std::string key = line.substr(0, eq);
        const auto begin = key.find_first_not_of(" \t");
        if (begin == std::string::npos) continue;
        key = key.substr(begin, key.find_last_not_of(" \t") - begin + 1);
        if (key != "memory_mib") continue;
        uint64_t configured = 0; std::istringstream value(line.substr(eq + 1));
        if (value >> configured && configured > 0 && configured <= 1048576) return configured;
    }
    return host_mib <= 10 * 1024 ? 4096 : 5120;
}
inline bool setup_commit_available(uint64_t available_bytes, uint64_t guest_mib) {
    return available_bytes / (1024 * 1024) >= guest_mib + 256;
}
}