Giter Club home page Giter Club logo

Comments (6)

messi824 avatar messi824 commented on May 20, 2024

看代码终于明白了。以example_copustack.cpp为例,它在一个线程中分配了128个栈,则128n(n>=0)号协程都使用0号栈,128n+1使用1号栈,以此类推。
当协程运行时,运行到co_swap,如果0号协程是第一次使用pending_co->stack_mem->ocupy_co,则其为null,此时将pending_co赋值给它;如果第二次128号协程过来运行,判断出这个变量其实保存的是0号协程的内容,此时,需要执行copy操作,把0号协程的栈信息保存到malloc的空间。
感觉这样并不能节省多少空间啊。。。虽然运行栈的空间变小了,但是新赠了额外保存协程信息的内存,会不会得不偿失啊?

from libco.

willkozheng avatar willkozheng commented on May 20, 2024

这个优化点,主要在于,栈的内存峰值不一定是栈切换时发生的。
例如,
栈a的内存峰值为8k,发生切换时只需使用4k,那使用共享的可以节约4k。

from libco.

messi824 avatar messi824 commented on May 20, 2024

这个感觉优化有限,因为并不能控制一定在4k的时候切换,如果切换的时候就是8k,那不是还浪费了8k的空间存储?

from libco.

willkozheng avatar willkozheng commented on May 20, 2024

1.不会存在浪费
2.是否能节省,取决于切换时是否峰值。正常来说,一个协程不可能每次切换都处于峰值。
这个是针对场景性的优化,当然不能保证每份代码都起作用,但是越复杂的逻辑这个效果会越明显。

from libco.

messi824 avatar messi824 commented on May 20, 2024

学习了,非常感谢!

from libco.

wechatsunny avatar wechatsunny commented on May 20, 2024

close

from libco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.