Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411512 Posts in 69376 Topics- by 58430 Members - Latest Member: Jesse Webb

April 26, 2024, 07:53:59 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Coroutine Cost
Pages: [1]
Print
Author Topic: Coroutine Cost  (Read 891 times)
Sundrop
Level 1
*

Grandma cooks best!


View Profile WWW
« on: September 09, 2019, 05:53:28 PM »

Silly question:

Code:
IEnumerator Task ()
{
    yield return AnotherTask ();
}

IEnumerator AnotherTask()
{
    while (enabled)
    {
        // do something

        yield return null;
    }
}

Will this code cost 2 coroutines worth of RAM or 1? Seems silly to ask but I wanna make sure since I'm doing this a lot.  Embarrassed
« Last Edit: December 28, 2019, 11:41:36 PM by Sundrop » Logged

Ordnas
Level 10
*****



View Profile WWW
« Reply #1 on: September 23, 2019, 08:19:12 AM »

It is a Synchronous Coroutine, execution of Task() is suspended during the execution of AnotherTask(), so internally there is no need to start another coroutine. You can optimize doing:

IEnumerator Task ()
{
while (enabled)
    {
        // do something

        yield return null;
    }
}

It has the same result, but it will be executed in the same frame instead of waiting the next frame.
Logged

Games:

EmeraldPawn
Level 0
*


View Profile WWW
« Reply #2 on: September 27, 2019, 07:18:23 AM »

Do it the way that causes less headache for you in the future, you really don't need to optimize for RAM useage for a coroutine. Write code that you can read and modify later, and optimize when you need to but base it in profiler data, not a hunch. Remember, premature optimization is the root of all evil.
Cheers! Coffee
Logged

Currently working on: Strobophagia - Rave Horror
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic