Cotton code
35 lines · 1.4 KB · SwiftRaw
// What the Sites app tells the core of its pages' memory (`SitesMemory`, SITES 5), moved here from Comms' session// screen when Sites left Comms (COMMS WITHOUT MAIL, 26 Nov 2026): figures only, nothing of a page.#if os(iOS)import Foundationimport os/// The core's `SitesMemory` (SITES 5): figures only, nothing of a page.struct SitesFigures: Encodable, Equatable {    var alive: UInt32 = 0    var mostAlive: UInt32 = 0    var limit: UInt32    var letGo: UInt64 = 0    var warnings: UInt64 = 0    var webEnded: UInt64 = 0    var peakFootprintMb: UInt64?    var leastHeadroomMb: UInt64?    /// The app's own footprint now, in MB (what iOS counts against it). A web page's own process is not given to an app.    static func footprintMB() -> UInt64? {        var info = task_vm_info_data_t()        var count = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<natural_t>.size)        let result = withUnsafeMutablePointer(to: &info) {            $0.withMemoryRebound(to: integer_t.self, capacity: Int(count)) { task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), $0, &count) }        }        return result == KERN_SUCCESS ? info.phys_footprint / 1_048_576 : nil    }    /// How much more the app may take before iOS ends it, in MB (none on the simulator).    static func headroomMB() -> UInt64? {        let left = os_proc_available_memory()        return left > 0 ? UInt64(left) / 1_048_576 : nil    }}#endif