Skip to content

Instantly share code, notes, and snippets.

@dskjal
Last active September 24, 2016 23:13
Show Gist options
  • Save dskjal/eccb7df4ca958811a02d71ef6652caeb to your computer and use it in GitHub Desktop.
Save dskjal/eccb7df4ca958811a02d71ef6652caeb to your computer and use it in GitHub Desktop.
Unity は foreach でヒープにメモリを確保するか?
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