4 ms·
Ah. What kind of asynchronous task executes so fast that a heap allocation is measurable?
by continuational 7y ago
Ah. What kind of asynchronous task executes so fast that a heap allocation is measurable?
- shepmaster 7y agoI like to think of it from the other direction. I'm super excited to use futures and async/await in embedded hardware, where "the heap" might not even exist. Hardware interrupts can be treated as events that wake the executor. That lets me write some code like this: async fn bracketed_echo() -> ! { loop { let mut buf = 0; Serial.rx(&mut buf).await; Serial.tx(b'>').await; Serial.tx(buf).await; Serial.tx(b'<').await; } } This reads from the serial port and echos it back inside of `><`. The code reads very cleanly, does not require the heap, and should be very efficient. The caveat is that I am also trying to target a platform that Lust / LLVM doesn't support completely yet, so I haven't gotten this to actually work well. I bet the people using the Cortex processor are far ahead of me though.
- zwirbl 7y agoThat's exactly what I am looking forward to, the state machine generation can make a lot of code targeting embedded platforms, especially the IO part, much more comfortable. Might I ask which controller you are using? With Rust I'm still on a Cortex, but looking to apply it on other architectures in the future
- gpderetta 7y agoA network read or write can be in the order of hundreds of nanoseconds when using an accelerated userspace networking stack. Allocation can be a good chunk of that.