私は現在MonoGameで遊んでおり、SpriteBatch.Draw()メソッドを調査していました。
1秒間に数万回呼び出すことができるメソッドの内部には、次のように表示されます。
public void Draw (Texture2D texture,
Rectangle destinationRectangle,
Rectangle? sourceRectangle,
Color color,
float rotation,
Vector2 origin,
SpriteEffects effect,
float depth)
{
CheckValid(texture);
DrawInternal(texture,
new Vector4(destinationRectangle.X, //<-------------- Oh Noes! :O
destinationRectangle.Y,
destinationRectangle.Width,
destinationRectangle.Height),
sourceRectangle,
color,
rotation,
new Vector2(origin.X * ((float)destinationRectangle.Width (float)texture.Width), <-- Oh Noes!
origin.Y * ((float)destinationRectangle.Height / (float)texture.Height)),
effect,
depth);
}
60分の1秒程度ごとに何千もの新しいベクトルが割り当てられているように見えます。
MonoGameは、(とりわけ)モバイル開発を目的としたプラットフォームです。私はDalvikで実行されるモバイル開発を行いましたが、この方法で割り当てることは決して良い考えではありませんでした。低速のモバイルプロセッサでは、収集が必要なオブジェクトが蓄積すると、最終的にGCが実行され、パフォーマンスが著しく低下します(一部のデバイスでは最大200ミリ秒)。それは私の質問に私を導きます:
CLR / Mono GCの実行方法、またはこのパフォーマンスヒットの発生を防ぐその他の要因について何かありますか、それとも、MonoGameは最も呼び出される関数の1つで実行すべきでないことを実行していますか?