Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(3 edits)

To give you an example of how to get rid of string allocations think about creating lookup tables for your values (enum is easy and natural candidate for that). This is how you create an lookup table for enums:

public static readonly Dictionary<ItemType,string> ItemTypeStrings = new Dictionary<ItemType,string>{
            { ItemType.Metal, "Metal" } ,
            { ItemType.Food, "Food" } ,
            { ItemType.Water, "Water" } ,
            { ItemType.Mineral, "Mineral" } ,
            { ItemType.Dirt, "Dirt" } ,
            { ItemType.WasteWater, "Waste Water" } ,
            { ItemType.LOX, "LOX" } ,
            { ItemType.LH2, "LH2" } ,
            { ItemType.AsteroidaldWater, "Asteroidald Water" } ,
            { ItemType.MetalOre, "Metal Ore" } ,
            { ItemType.Component , "Component" } ,
            { ItemType.None , "None" } ,
        };

And that will give you an ability to replace every:

string myTypeString = itemStack.Type.ToString();//allocation

with:

string myTypeString = ItemTypeStrings[ itemStack.Type ];

which will allocate no memory at all (==what we want)