Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1369500 Posts in 64351 Topics- by 56368 Members - Latest Member: concrete_games

November 20, 2019, 01:42:58 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 273 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: September 09, 2019, 08:52:48 PM by Sundrop » Logged

Ordnas
Level 7
**



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

Devlogs:

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