Download src/core/conversation_memory.cpp from WineryLabs/Winery-Strata: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/WineryLabs/Winery-Strata/resolve/main/src/core/conversation_memory.cpp
- Command line
-
hf download hf://WineryLabs/Winery-Strata/src/core/conversation_memory.cpp
-
curl -L -o conversation_memory.cpp https://huggingface.co/WineryLabs/Winery-Strata/resolve/main/src/core/conversation_memory.cpp
1.52 kB
| namespace strata::core { | |
| std::optional<uint64_t> conversation_mem_available(std::istream& meminfo) { | |
| std::optional<uint64_t> result; | |
| std::string line; | |
| while (std::getline(meminfo, line)) { | |
| std::istringstream fields(line); | |
| std::string key, value, unit, extra; | |
| if (!(fields >> key) || key != "MemAvailable:") continue; | |
| if (result || !(fields >> value >> unit) || unit != "kB" || (fields >> extra)) return {}; | |
| uint64_t kb = 0; | |
| const auto parsed = std::from_chars(value.data(), value.data() + value.size(), kb); | |
| if (parsed.ec != std::errc{} || parsed.ptr != value.data() + value.size() || | |
| kb > std::numeric_limits<uint64_t>::max() / 1024) return {}; | |
| result = kb * 1024; | |
| } | |
| if (meminfo.bad() || (meminfo.fail() && !meminfo.eof())) return {}; | |
| return result; | |
| } | |
| std::optional<uint64_t> conversation_available_memory() { | |
| MEMORYSTATUSEX status{}; | |
| status.dwLength = sizeof status; | |
| if (GlobalMemoryStatusEx(&status)) return status.ullAvailPhys; | |
| return {}; | |
| std::ifstream meminfo("/proc/meminfo"); | |
| if (!meminfo) return {}; | |
| return conversation_mem_available(meminfo); | |
| return {}; | |
| } | |
| } // namespace strata::core | |