困った時の自分用メモ

読んだ本を考察してメモったり、自分でいじった物の感想をメモったりする場。週1更新を目指します。

Luaの話~LuaStateを作ると、どの程度メモリを消費するのか1~

▼検証コードメモ
    void Start () {
        Application.targetFrameRate = 60;

        StartDebugLog += "↓↓↓↓↓start↓↓↓↓↓\n\n";

        uint monoSize = Profiler.GetMonoHeapSize();
        uint monoUsed = Profiler.GetMonoUsedSize();
        uint tempSize = Profiler.GetTempAllocatorSize();
        uint totalUsed = Profiler.GetTotalAllocatedMemory();
        uint totalSize = Profiler.GetTotalReservedMemory();

        StartDebugLog += string.Format("mono:{0}/{1}kb\ntotal:{2}/{3}kb\ntemp:{4}kb\n\n", monoUsed/1024, monoSize/1024, totalUsed/1024, totalSize/1024, tempSize/1024);
        StartDebugLog += "↑↑↑↑↑start↑↑↑↑↑\n\n";

        StartCoroutine(CoroutineStart());
    }

    private IEnumerator CoroutineStart() {
        GameSceneManager.Instance.Initialize();
        GameObjectCacheManager.Instance.Initialize();
        AssetBundleManager.Instance.Initialize();
        ResourceManager.Instance.Init();
        RijindaelManager.Instance.Init();
        VersionFileManager.Instance.Initialize();

        yield return null;
        yield return StartCoroutine(LuaInit());
        yield return null;

        ClickDebugLog = "↓↓↓↓↓click↓↓↓↓↓\n\n";

        uint monoSize = Profiler.GetMonoHeapSize();
        uint monoUsed = Profiler.GetMonoUsedSize();
        uint tempSize = Profiler.GetTempAllocatorSize();
        uint totalUsed = Profiler.GetTotalAllocatedMemory();
        uint totalSize = Profiler.GetTotalReservedMemory();

        ClickDebugLog += string.Format("mono:{0}/{1}kb\ntotal:{2}/{3}kb\ntemp:{4}kb\n\n", monoUsed/1024, monoSize/1024, totalUsed/1024, totalSize/1024, tempSize/1024);
        ClickDebugLog += "↑↑↑↑↑click↑↑↑↑↑\n\n";
        OutputText.text = StartDebugLog + ClickDebugLog;
//        yield return null;
    }

▼UnityEditor上(ターゲットはAndroid
〇LuaState作成をする
mono:4940/20852kb
total:48811/205184kb
temp:16384kb



mono:5312/20852kb
total:49065/205184kb
temp:16384kb

〇LuaState作成をしない
mono:4944/20852kb
total:49083/205184kb
temp:16384kb



mono:5028/20852kb
total:49323/205184kb
temp:16384kb

約300kbくらい?

Android実機
〇LuaState作成をする
mono:0/0kb
total:5748/8823kb
temp:1024kb



mono:0/0kb
total:5844/9249kb
temp:1024kb

〇LuaState作成をしない
mono:0/0kb
total:5751/8828kb
temp:1024kb



mono:0/0kb
total:5843/8991kb
temp:1024kb

ほぼ変わり無し…?

 

▼タスクマネージャのリソースモニターで調べてみた

仕方ないので、EXE版をビルドし、PC上からリソースモニタでメモリの遷移を確認。

結論からかくと、ワーキングとプライベートがおよそ400kb増えていた。

10000個作ると、300mb程増えていた。

何にせよ、一個LuaVM立ち上げる程度だったら、そこまで神経質になるほどではなさそうだ。

▼ここまでの結論
参照の仕方が悪いのか、とりあえずメモリ使用量プロパティ上には明確に変化が現れる数値は確認できなかったが、リソースモニターで見た所、大幅にメモリ使用量が増えるような挙動は見せなかった。