Invoking Func Memory Allocation workaroud
Hi, Invoking a specified Func every frame allocates memory, do you maybe know workaround for this? I'm doing func list to execute in order, when func returns true -> next func in executed:
private LinkedList<Func<bool>> actionList = new LinkedList<Func<bool>>();
void Awake()
{
actionList.AddLast(() => FunctionDoSomething());
actionList.AddLast(() => FunctionDoSomething2());
}
void Update()
{
if (actionList.Count != 0) {
while( actionList.First().Invoke() )
{
actionList.RemoveFirst();
if (actionList.Count == 0) break;
}
}
}
private bool FunctionDoSomething(){ return (something == "nope") }
private bool FunctionDoSomething2(){ return (something == "meh") }
Comment
Answer by ptm_oo · Jun 01, 2020 at 09:09 AM
ANSWER:
if(!actionPause){
if (actionList.Count > 0 ) {
Func<bool> _fref = actionList.First ();
while( _fref() )
{
actionList.RemoveFirst();
if (actionList.Count == 0) break;
_fref = actionList.First ();
}
}
}
Your answer
Follow this Question
Related Questions
List.FindIndex 1 Answer
Use a class like a function 1 Answer
Technically Match 3 but not really 0 Answers
call any method 1 Answer