C 中堆栈不断增长的协程
我想在 C (Linux) 中使用协程,但我不想为每个协程浪费大量空间。我想知道如何使用给定 MAP_GROWSDOWN 的 mmap()
为堆栈分配空间,但我在某处读到它已损坏,您对此了解更多吗?
I want to use coroutines in C (Linux), but I don't want to waste lots of space for each one. I'm wondering about allocating the space for the stack with mmap()
given MAP_GROWSDOWN
, but I read somewhere that it was broken, do you know any more about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不用担心。您的协程可以有一个大堆栈,但它不会导致任何性能或资源问题,除非堆栈实际上使用。在此之前,不会为内存的逻辑页分配物理页。如果使用了,那么您就需要它,不是吗?
只需使用大小合适的堆栈即可完成。
Don't worry about it. Your coroutine can have a large stack but it will not cause any performance or resource problems unless the stack is actually used. The logical pages of memory will not be assigned physical pages until that point. And if it is used, well you needed it then didn't you?
Just use a decent sized stack and have done with it.