C
C#2y ago
eimiieee

❔ Question about cache

Hello, I have the following code.
private Class1 class1;
private Class2 class2;

private void Start(){
class1 = Class1.Instance;
class2 = Class2.Instance;
}

private void Update()
{
UpdateState();
}

private void UpdateState()
{
Helpers(class1);
// etc, removed for breiviety
}

private void Helpers(Class1 class1);
{
if(class1.something > 0)
{
// Do stuff
}
}
private Class1 class1;
private Class2 class2;

private void Start(){
class1 = Class1.Instance;
class2 = Class2.Instance;
}

private void Update()
{
UpdateState();
}

private void UpdateState()
{
Helpers(class1);
// etc, removed for breiviety
}

private void Helpers(Class1 class1);
{
if(class1.something > 0)
{
// Do stuff
}
}
I was reccomended to cache Class1 inside the helpers method as such var myClass = class1.something; However, my question is if that is necessary since i already cached the class in Start() and then pass that in the helpers parameters I hope my question was understandable 🙂
2 Replies
eimiieee
eimiieeeOP2y ago
Recommendation in question; Cache the something field of Class1 to avoid accessing it multiple times during the execution of the method.
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server