Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/ThreemaFramework/Utilities/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 2 kB image not shown  

Quelle  DeviceUtility.swift   Sprache: JAVA

 

import Foundation

public enum DeviceUtility {

    /// Get total size and total free size of the device.
    ///
    /// - Returns:
    ///    - totalSize: total size in bytes of device
    ///    - totalFreeSize: total free size in bytes on device
    public static func getStorageSize() -> (totalSize: Int64?, totalFreeSize: Int64?) {
        var size: Int64?
        var freeSize: Int64?

        let homeDirectory = URL(fileURLWithPath: NSHomeDirectory())
        if let systemResources = try? homeDirectory
            .resourceValues(forKeys: [.volumeTotalCapacityKey, .volumeAvailableCapacityForImportantUsageKey]) {
            size = systemResources.allValues[.volumeTotalCapacityKey] as? Int64
            freeSize = systemResources.allValues[.volumeAvailableCapacityForImportantUsageKey] as? Int64
        }

        return (size, freeSize)
    }

    /// Amount of physical memory.
    /// - Returns: Amount of bytes
    public static func getTotalMemory() -> UInt64 {
        ProcessInfo.processInfo.physicalMemory
    }

    /// Amount of physical memory in used.
    /// - Returns: Amount of bytes
    public static func getUsageMemory() -> Float? {
        var info = mach_task_basic_info()
        var count = mach_msg_type_number_t(MemoryLayout.size(ofValue: info) / MemoryLayout<integer_t>.size)
        let kerr = withUnsafeMutablePointer(to: &info) { infoPtr in
            infoPtr
                .withMemoryRebound(
                    to: integer_t.self,
                    capacity: Int(count)
                ) { (machPtr: UnsafeMutablePointer<integer_t>) in
                    task_info(
                        mach_task_self(),
                        task_flavor_t(MACH_TASK_BASIC_INFO),
                        machPtr,
                        &count
                    )
                }
        }
        guard kerr == KERN_SUCCESS else {
            return nil
        }
        return Float(info.resident_size) // / (1024 * 1024)
    }

    private static func mach_task_self() -> task_t {
        mach_task_self_
    }
}

Messung
CHZG
849710093

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-11-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.