I have a C# class which I need to use to instantiate millions of objects. So I need to make the class light weight and super fast. I declared some functions into it. So my concern is, declaring all those functions will make the class slow or consume more memory. I also have choice to declare those functions into another class. Here is the class:
internal class Var
{
public dynamic data;
public int index;
public VarTypes type;
public bool doClone = false;
public Var Clone(bool doClone)
{
var tmpVar = Clone();
tmpVar.doClone = doClone;
return tmpVar;
}
public Var Clone()
{
if (doClone)
return new Var() { data = data, index = index, type = type };
else
return this;
}
public void Clone(Var old)
{
this.data = old.data;
this.index = old.index;
this.type = old.type;
}
public override string ToString()
{
if (type == VarTypes.Function)
{
StringBuilder builder = new StringBuilder("function ");
if (data.Count == 4)
builder.Append(data[3].ToString());
builder.Append("(");
for (int i = 1; i < data[1][1].Count; i++)
builder.Append(data[1][1][i].ToString() + ",");
if (builder[builder.Length - 1] == ',')
builder.Remove(builder.Length - 1, 1);
builder.Append(")");
return builder.ToString();
}
else
return data.ToString();
}
}