【问题标题】:UWP device total memoryUWP 设备总内存
【发布时间】:2016-08-17 23:15:48
【问题描述】:

如何确定设备的总内存?我想在低内存设备上使用顺序程序流,在高内存设备上使用更异步的流程。

示例:在具有 1GB 内存的设备上,我的程序可以运行,但在 512MB 的设备上,我的程序遇到了 OutOfMemoryException,因为它正在异步缓存来自多个站点的图像。

【问题讨论】:

    标签: c# memory size win-universal-app


    【解决方案1】:

    MemoryManager 类有一些静态属性来获取应用程序的当前使用情况和限制。

    // Gets the app's current memory usage.
    MemoryManager.AppMemoryUsage
    
    // Gets the app's memory usage level.
    MemoryManager.AppMemoryUsageLevel
    
    // Gets the app's memory usage limit.
    MemoryManager.AppMemoryUsageLimit
    

    您可以使用 MemoryManager.AppMemoryUsageLimitChanging 事件对更改的限制做出反应

    private void OnAppMemoryUsageLimitChanging(
        object sender, AppMemoryUsageLimitChangingEventArgs e)
    {
        Debug.WriteLine(String.Format("AppMemoryUsageLimitChanging: old={0} MB, new={1} MB", 
            (double)e.OldLimit / 1024 / 1024,
            (double)e.NewLimit / 1024 / 1024));
    }
    

    您可以使用应用程序的内存限制来决定如何最好地管理您的内存分配。

    【讨论】:

    • 如何获取设备中安装的总内存?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 2016-03-13
    • 1970-01-01
    • 2012-04-06
    相关资源
    最近更新 更多