UWP 设备总内存

Dav*_*lin 5 c# memory size win-universal-app

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

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

Gle*_*mas 6

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
Run Code Online (Sandbox Code Playgroud)

您可以使用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));
}
Run Code Online (Sandbox Code Playgroud)

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

  • 如何获取设备中安装的总内存? (2认同)