Mais conteúdo relacionado
C# ゲームプログラミングはホントにメモリのことに無頓着でいいの?
- 35. 35
メモリ確保が発生しないプログラミング (1/2)
2018/3/19 春合宿2018講座;C#ゲームプログラムとメモリ;crys
class GoodScene
{
private Bullet[] bullets;
public GoodScene()
{
bullets = new Bullet[256];
}
public void MainLoop()
{
bullets[index].position = ...
}
}
class BadScene
{
private List<Bullet> bullets;
public BadScene() {}
public void MainLoop()
{
var b = new Bullet();
bullets.Add(b)
b.position = ...
}
}
シーン開始時のロードで、必要な情報をすべてメモリに載せる
- 44. 44
Coroutine (3/3)
2018/3/19 春合宿2018講座;C#ゲームプログラムとメモリ;crys
var waitForEndOfFrame = new WaitForEndOfFrame();
IEnumerator TimerCoroutine()
{
// 300フレーム待つ
for(int i=0; i < 300; i++){
yield return waitForEndOfFrame;
}
// do something
}
StartCoroutine(TimerCoroutine());
そもそもコルーチンを
生成すると
メモリ確保される…
コルーチンなしで頑張る…?
- 45. 45
などなど
詳しい情報は「Unity GC Alloc」みたいなのでググって
うにばな メモリ使用量の最適化・ヒープメモリ ほか – livedoor Blog
http://blog.livedoor.jp/akinow/archives/52474053.html
↑ただし、foreach で List を回すとメモリ確保する(クソ)仕様は
Unity 5.5 で修正済
neue cc - C#のGCゴミとUnity(5.5)のコンパイラアップデートによるListの
foreach問題解決について
http://neue.cc/2016/08/05_537.html
2018/3/19 春合宿2018講座;C#ゲームプログラムとメモリ;crys