首页 > 解决方案 > Memory cost of sending items over mpsc channel

问题描述

I have two threads that read a stream of messages from two sources and then forward them to a third sink where they get processed in order.

I'm concerned about the overhead of copying data as my messages are on each thread's stack and to move them through mpsc, every bit has to be copied over to the sink's stack.

If I try to mitigate this by putting my message in a Box, then only the pointer would be sent over to the new stack but still a copy happens from source's stack to heap.

And I'm not entirely sure if my message is on heap or stack, as I saw a blog post in rust-lang.org the other day which claimed a vec![1,2,3] lives on stack, which if true, is something I wouldn't have guessed.

标签: rust

解决方案


推荐阅读