From 0845316a6c7de188434fa5376b338c4901134c07 Mon Sep 17 00:00:00 2001 From: Lior Tal Date: Wed, 14 Oct 2015 15:04:09 +0000 Subject: [PATCH] Improve memory behaviour by pre-allocating the right amount of memory. --HG-- branch : liortal/improve-memory-behaviour-by-preallocatin-1444835033293 --- Scripts/NicerOutline.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Scripts/NicerOutline.cs b/Scripts/NicerOutline.cs index 797d69f..bb0c68c 100644 --- a/Scripts/NicerOutline.cs +++ b/Scripts/NicerOutline.cs @@ -8,6 +8,9 @@ namespace UnityEngine.UI.Extensions [AddComponentMenu("UI/Effects/Extensions/Nicer Outline")] public class NicerOutline : BaseMeshEffect { + // A constant factor used when allocating the vertex list. + private const int GROWTH_FACTOR = 24; + [SerializeField] private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f); @@ -128,7 +131,7 @@ namespace UnityEngine.UI.Extensions { return; } - List < UIVertex > verts = new List(); + List < UIVertex > verts = new List(GROWTH_FACTOR * mesh.vertices.Length); using (var helper = new VertexHelper(mesh)) { helper.GetUIVertexStream(verts);