Last active
September 24, 2016 23:13
-
-
Save dskjal/eccb7df4ca958811a02d71ef6652caeb to your computer and use it in GitHub Desktop.
Unity は foreach でヒープにメモリを確保するか?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour { | |
readonly int ARRAY_LENGTH = 1000; | |
int[] values; | |
GameObject[] objects; | |
void Awake() { | |
objects = new GameObject[ARRAY_LENGTH]; | |
for(var i = 0; i < objects.Length; ++i) { | |
objects[i] = new GameObject(); | |
} | |
values = new int[ARRAY_LENGTH]; | |
} | |
// Update is called once per frame | |
void Update () { | |
Profiler.BeginSample("foreach"); | |
foreach (var i in values) { | |
values[0] += i; | |
} | |
foreach (var o in objects) { | |
o.isStatic = true; | |
} | |
Profiler.EndSample(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment