デコシノニッキ

ホロレンジャーの戦いの記録

小ネタ HoloLensのメモリ使用量上限

ドキュメントでは900MBまでね、と書かれているのですがやっぱり事象を確認しないとすっきりしないので確認 t.co

検証用コード

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

public class Example : MonoBehaviour
{
    public Text m_text;
    private string limit;

    private byte[] M100;
    private byte[] M200;
    private byte[] M300;
    private byte[] M400;
    private byte[] M500;
    private byte[] M600;
    private byte[] M700;
    private byte[] M800;
    private byte[] M900;
    private List<byte[]> bytes = new List<byte[]>();

    private WaitForSeconds time = new WaitForSeconds(1);
    private StringBuilder sb = new StringBuilder();
    private bool IsCatchedOutOfMemory = false;

    private void Start()
    {
        StartCoroutine(Alloc());
    }

    //ヒープ領域を100MBずつ確保していく
    private IEnumerator Alloc()
    {
        M100 = new byte[104857600];
        yield return time;
        M200 = new byte[104857600];
        yield return time;
        M300 = new byte[104857600];
        yield return time;
        M400 = new byte[104857600];
        yield return time;
        M500 = new byte[104857600];
        yield return time;
        M600 = new byte[104857600];
        yield return time;
        M700 = new byte[104857600];
        yield return time;
        M800 = new byte[104857600];
        yield return time;
        M900 = new byte[104857600]; //ここでException
        yield return time;
    }

    private void Update()
    {
        var memory = GC.GetTotalMemory(false) * 0.00000095367432;

        var limit =
#if WINDOWS_UWP
        Windows.System.MemoryManager.AppMemoryUsageLimit * 0.00000095367432;
#else
        SystemInfo.systemMemorySize / 1024;
#endif

        sb.Clear();
        sb.AppendFormat("UsageLimit: {0:f3} MB", limit).AppendLine();
        sb.AppendFormat("TotalMemory: {0:f3} MB", memory).AppendLine();
        m_text.text = sb.ToString();
    }
}

本当はGC止めて,ボクシングとかでごみを増やしまくって殺そうと思ったのですが安定のUWPってやつです。

www.shibuya24.info

[デコシノニッキ]は、Amazon.co.jpを宣伝しリンクすることによってサイトが紹介料を獲得できる手段を提供することを目的に設定されたアフィリエイト宣伝プログラムである、Amazonアソシエイト・プログラムの参加者です。」