小编rea*_*hao的帖子

变长数组和动态内存分配有什么区别?

int a[n];
Run Code Online (Sandbox Code Playgroud)

int * a;
a = malloc(n * sizeof(int));
Run Code Online (Sandbox Code Playgroud)

谁能分别解释一下这两种方法的优缺点?(效率、安全性等)

c

3
推荐指数
1
解决办法
572
查看次数

tokio::select! 和 tokio::select! 之间有什么区别?循环内的 A、B 和 tokio::spawn 两个任务,每个任务运行 A、B 之一?

我是异步编程的新手,因此努力解决不同方法的行为差异。

考虑 tokio 在 github 存储库 chat.rs 中给出的示例:

// snip
    loop {
        tokio::select! {
            // A message was received from a peer. Send it to the current user.
            Some(msg) = peer.rx.recv() => {
                // do something
            }
            result = peer.lines.next() => match result {
                // A message was received from the current user, we should
                // broadcast this message to the other users.
                Some(Ok(msg)) => {
                    // do something
                }
                Some(Err(e)) => {
                    // handle error
                }
                // The stream …
Run Code Online (Sandbox Code Playgroud)

rust rust-tokio

3
推荐指数
1
解决办法
2392
查看次数

标签 统计

c ×1

rust ×1

rust-tokio ×1