int a[n];
Run Code Online (Sandbox Code Playgroud)
与
int * a;
a = malloc(n * sizeof(int));
Run Code Online (Sandbox Code Playgroud)
谁能分别解释一下这两种方法的优缺点?(效率、安全性等)
我是异步编程的新手,因此努力解决不同方法的行为差异。
考虑 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)